// Path: src/main/java/org/kontalk/crypto/Coder.java
// public final class Coder {
//     private static final Logger LOGGER = Logger.getLogger(Coder.class.getName());
// 
//     private Coder() {
//     }
// 
//     /**
//      * Encryption status of a message.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Encryption {NOT, ENCRYPTED, DECRYPTED}
// 
//     /**
//      * Signing status of a message.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Signing {NOT, SIGNED, VERIFIED, UNKNOWN}
// 
//     /**
//      * Errors that can occur during de-/encryption and verification.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Error {
//         /** Some unknown error. */
//         UNKNOWN_ERROR,
//         /** Own personal key not found. Unused. */
//         MY_KEY_UNAVAILABLE,
//         /** Public key of sender not found. */
//         KEY_UNAVAILABLE,
//         /** My private key does not match. */
//         INVALID_PRIVATE_KEY,
//         /** Invalid data / parsing failed. */
//         INVALID_DATA,
//         /** No integrity protection found. */
//         NO_INTEGRITY,
//         /** Integrity check failed. */
//         INVALID_INTEGRITY,
//         /** Invalid data / parsing failed of signature. */
//         INVALID_SIGNATURE_DATA,
//         /** Signature does not match sender. */
//         INVALID_SIGNATURE,
//         /** Recipient user id in decrypted data does not match id in my key. */
//         INVALID_RECIPIENT,
//         /** Sender user id in decrypted data does not match id in sender key. */
//         INVALID_SENDER,
// 
//         //INVALID_MIME,
//         //INVALID_TIMESTAMP,
//     }
// 
//     private static final HashMap<Contact, PGPCoderKey> KEY_MAP = new HashMap<>();
// 
//     public static Optional<PGPCoderKey> contactkey(Contact contact) {
//         if (KEY_MAP.containsKey(contact)) {
//             PGPCoderKey key = KEY_MAP.get(contact);
//             if (key.fingerprint.equals(contact.getFingerprint()))
//                 return Optional.of(key);
//         }
// 
//         byte[] rawKey = contact.getKey();
//         if (rawKey.length != 0) {
//             PGPCoderKey key = PGPUtils.readPublicKey(rawKey).orElse(null);
//             if (key != null) {
//                 KEY_MAP.put(contact, key);
//                 return Optional.of(key);
//             }
//         }
// 
//         LOGGER.warning("key not found for contact: "+contact);
//         return Optional.empty();
//     }
// 
//     /**
//      * Decrypt and verify the body of a message. Sets the encryption and signing
//      * status of the message and errors that may occur are saved to the message.
//      */
//     public static boolean decryptMessage(PersonalKey myKey, DecryptMessage message) {
//         return Decryptor.decryptMessage(message, myKey);
//     }
// 
//     /**
//      * Decrypt and verify a downloaded attachment file. Sets the encryption and
//      * signing status of the message attachment and errors that may occur are
//      * saved to the attachment.
//      */
//     public static void decryptAttachment(PersonalKey myKey, InAttachment attachment, Contact sender) {
//         Decryptor.decryptAttachment(attachment, myKey, sender);
//     }
// 
//     /**
//      * Creates encrypted and signed message body.
//      * Errors that may occur are saved to the message.
//      * @return the encrypted and signed text.
//      */
//     public static String encryptMessageRFC3923(PersonalKey myKey, OutMessage message) {
//         return new Encryptor(myKey, message).encryptMessageRFC3923();
//     }
// 
//     public static String encryptStanzaRFC3923(PersonalKey myKey, OutMessage message, String xml) {
//         return new Encryptor(myKey, message).encryptStanzaRFC3923(xml);
//     }
// 
//     /** Encrypt an arbitrary UTF-8 string as a Base64 encoded OpenPGP Message. */
//     public static String encryptString(PersonalKey myKey, OutMessage message, String plainText) {
//         return new Encryptor(myKey, message).encryptString(plainText);
//     }
// 
//     public static Optional<File> encryptAttachment(PersonalKey myKey, OutMessage message, File file) {
//         return new Encryptor(myKey, message).encryptAttachment(file);
//     }
// }


import java.util.EnumSet;
import org.kontalk.crypto.Coder;
        if (signing == Coder.Signing.SIGNED)
            assert mSigning == Coder.Signing.UNKNOWN;
        if (signing == Coder.Signing.VERIFIED)
            assert mSigning == Coder.Signing.SIGNED ||
                    mSigning == Coder.Signing.UNKNOWN;

        mSigning = signing;
    }

    public EnumSet<Coder.Error> getErrors() {
        // better return a copy
        return mErrors.clone();
    }

    public void setSecurityErrors(EnumSet<Coder.Error> errors) {
        mErrors.clear();
        mErrors.addAll(errors);
    }

    @Override
    public String toString() {
        return "CSTAT:encr="+mEncryption+",sign="+mSigning+",err="+mErrors;
    }

    static CoderStatus createInsecure() {
        return new CoderStatus(Coder.Encryption.NOT, Coder.Signing.NOT,
                EnumSet.noneOf(Coder.Error.class));
    }

    static CoderStatus createEncrypted() {
// Path: src/main/java/org/kontalk/crypto/Coder.java
// public final class Coder {
//     private static final Logger LOGGER = Logger.getLogger(Coder.class.getName());
// 
//     private Coder() {
//     }
// 
//     /**
//      * Encryption status of a message.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Encryption {NOT, ENCRYPTED, DECRYPTED}
// 
//     /**
//      * Signing status of a message.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Signing {NOT, SIGNED, VERIFIED, UNKNOWN}
// 
//     /**
//      * Errors that can occur during de-/encryption and verification.
//      * Do not modify, only add! Ordinal used in database.
//      */
//     public enum Error {
//         /** Some unknown error. */
//         UNKNOWN_ERROR,
//         /** Own personal key not found. Unused. */
//         MY_KEY_UNAVAILABLE,
//         /** Public key of sender not found. */
//         KEY_UNAVAILABLE,
//         /** My private key does not match. */
//         INVALID_PRIVATE_KEY,
//         /** Invalid data / parsing failed. */
//         INVALID_DATA,
//         /** No integrity protection found. */
//         NO_INTEGRITY,
//         /** Integrity check failed. */
//         INVALID_INTEGRITY,
//         /** Invalid data / parsing failed of signature. */
//         INVALID_SIGNATURE_DATA,
//         /** Signature does not match sender. */
//         INVALID_SIGNATURE,
//         /** Recipient user id in decrypted data does not match id in my key. */
//         INVALID_RECIPIENT,
//         /** Sender user id in decrypted data does not match id in sender key. */
//         INVALID_SENDER,
// 
//         //INVALID_MIME,
//         //INVALID_TIMESTAMP,
//     }
// 
//     private static final HashMap<Contact, PGPCoderKey> KEY_MAP = new HashMap<>();
// 
//     public static Optional<PGPCoderKey> contactkey(Contact contact) {
//         if (KEY_MAP.containsKey(contact)) {
//             PGPCoderKey key = KEY_MAP.get(contact);
//             if (key.fingerprint.equals(contact.getFingerprint()))
//                 return Optional.of(key);
//         }
// 
//         byte[] rawKey = contact.getKey();
//         if (rawKey.length != 0) {
//             PGPCoderKey key = PGPUtils.readPublicKey(rawKey).orElse(null);
//             if (key != null) {
//                 KEY_MAP.put(contact, key);
//                 return Optional.of(key);
//             }
//         }
// 
//         LOGGER.warning("key not found for contact: "+contact);
//         return Optional.empty();
//     }
// 
//     /**
//      * Decrypt and verify the body of a message. Sets the encryption and signing
//      * status of the message and errors that may occur are saved to the message.
//      */
//     public static boolean decryptMessage(PersonalKey myKey, DecryptMessage message) {
//         return Decryptor.decryptMessage(message, myKey);
//     }
// 
//     /**
//      * Decrypt and verify a downloaded attachment file. Sets the encryption and
//      * signing status of the message attachment and errors that may occur are
//      * saved to the attachment.
//      */
//     public static void decryptAttachment(PersonalKey myKey, InAttachment attachment, Contact sender) {
//         Decryptor.decryptAttachment(attachment, myKey, sender);
//     }
// 
//     /**
//      * Creates encrypted and signed message body.
//      * Errors that may occur are saved to the message.
//      * @return the encrypted and signed text.
//      */
//     public static String encryptMessageRFC3923(PersonalKey myKey, OutMessage message) {
//         return new Encryptor(myKey, message).encryptMessageRFC3923();
//     }
// 
//     public static String encryptStanzaRFC3923(PersonalKey myKey, OutMessage message, String xml) {
//         return new Encryptor(myKey, message).encryptStanzaRFC3923(xml);
//     }
// 
//     /** Encrypt an arbitrary UTF-8 string as a Base64 encoded OpenPGP Message. */
//     public static String encryptString(PersonalKey myKey, OutMessage message, String plainText) {
//         return new Encryptor(myKey, message).encryptString(plainText);
//     }
// 
//     public static Optional<File> encryptAttachment(PersonalKey myKey, OutMessage message, File file) {
//         return new Encryptor(myKey, message).encryptAttachment(file);
//     }
// }


// Path: src/main/java/org/kontalk/model/message/CoderStatus.java
import java.util.EnumSet;
import org.kontalk.crypto.Coder;

        if (signing == Coder.Signing.SIGNED)
            assert mSigning == Coder.Signing.UNKNOWN;
        if (signing == Coder.Signing.VERIFIED)
            assert mSigning == Coder.Signing.SIGNED ||
                    mSigning == Coder.Signing.UNKNOWN;

        mSigning = signing;
    }

    public EnumSet<Coder.Error> getErrors() {
        // better return a copy
        return mErrors.clone();
    }

    public void setSecurityErrors(EnumSet<Coder.Error> errors) {
        mErrors.clear();
        mErrors.addAll(errors);
    }

    @Override
    public String toString() {
        return "CSTAT:encr="+mEncryption+",sign="+mSigning+",err="+mErrors;
    }

    static CoderStatus createInsecure() {
        return new CoderStatus(Coder.Encryption.NOT, Coder.Signing.NOT,
                EnumSet.noneOf(Coder.Error.class));
    }

    static CoderStatus createEncrypted() {
        return new CoderStatus(Coder.Encryption.ENCRYPTED, Coder.Signing.UNKNOWN,