Ejemplo n.º 1
0
void Identity::setKey(const GpgME::Key &key)
{
    if (key.isNull()) {
        m_identity->setPGPEncryptionKey(QByteArray());
        m_identity->setPGPSigningKey(QByteArray());
        m_identity->setSMIMEEncryptionKey(QByteArray());
        m_identity->setSMIMESigningKey(QByteArray());
    } else if (key.protocol() == GpgME::OpenPGP) {
        m_identity->setPGPSigningKey(key.primaryFingerprint());
        m_identity->setPGPEncryptionKey(key.primaryFingerprint());
    } else if (key.protocol() == GpgME::CMS) {
        m_identity->setSMIMESigningKey(key.primaryFingerprint());
        m_identity->setSMIMEEncryptionKey(key.primaryFingerprint());
    }
}
Ejemplo n.º 2
0
bool Kleo::KConfigBasedKeyFilter::matches( const GpgME::Key & key ) const {
#ifdef MATCH
#undef MATCH
#endif
#define MATCH(member,method) \
  if ( member != DoesNotMatter && key.method() != bool( member == Set ) ) \
    return false
#define IS_MATCH(what) MATCH( m##what, is##what )
#define CAN_MATCH(what) MATCH( mCan##what, can##what )
    IS_MATCH( Revoked );
    IS_MATCH( Expired );
    IS_MATCH( Disabled );
    IS_MATCH( Root );
    CAN_MATCH( Encrypt );
    CAN_MATCH( Sign );
    CAN_MATCH( Certify );
    CAN_MATCH( Authenticate );
    MATCH( mHasSecret, isSecret );
#undef MATCH
    if ( mIsOpenPGP != DoesNotMatter &&
            bool( key.protocol() == GpgME::Context::OpenPGP ) != bool( mIsOpenPGP == Set ) )
        return false;
    if ( mWasValidated != DoesNotMatter &&
            bool( key.keyListMode() & GpgME::Context::Validate ) != bool( mWasValidated == Set ) )
        return false;
    switch ( mOwnerTrust ) {
    default:
    case LevelDoesNotMatter:
        break;
    case Is:
        if ( key.ownerTrust() != mOwnerTrustReferenceLevel )
            return false;
        break;
    case IsNot:
        if ( key.ownerTrust() == mOwnerTrustReferenceLevel )
            return false;
        break;
    case IsAtLeast:
        if ( (int)key.ownerTrust() < (int)mOwnerTrustReferenceLevel )
            return false;
        break;
    case IsAtMost:
        if ( (int)key.ownerTrust() > (int)mOwnerTrustReferenceLevel )
            return false;
        break;
    }
    const GpgME::UserID uid = key.userID(0);
    switch ( mValidity ) {
    default:
    case LevelDoesNotMatter:
        break;
    case Is:
        if ( uid.validity() != mValidityReferenceLevel )
            return false;
        break;
    case IsNot:
        if ( uid.validity() == mValidityReferenceLevel )
            return false;
        break;
    case IsAtLeast:
        if ( (int)uid.validity() < (int)mValidityReferenceLevel )
            return false;
        break;
    case IsAtMost:
        if ( (int)uid.validity() > (int)mValidityReferenceLevel )
            return false;
        break;
    }
    return true;
}