void XENCAlgorithmHandlerDefault::mapURIToKey()

in xsec/xenc/impl/XENCAlgorithmHandlerDefault.cpp [82:199]


void XENCAlgorithmHandlerDefault::mapURIToKey(const XMLCh* uri,
                                              const XSECCryptoKey* key,
                                              XSECCryptoKey::KeyType& kt,
                                              XSECCryptoSymmetricKey::SymmetricKeyType& skt,
                                              bool& isSymmetricKeyWrap,
                                              XSECCryptoSymmetricKey::SymmetricKeyMode& skm,
                                              unsigned int& taglen) const {

    if (key == NULL) {
        throw XSECException(XSECException::CipherError,
            "XENCAlgorithmHandlerDefault::mapURIToKey - trying to process a NULL key");
    }

    XSECCryptoSymmetricKey* keySymmetric;
    bool keyOK = false;

    kt = key->getKeyType();
    skt = XSECCryptoSymmetricKey::KEY_NONE;
    isSymmetricKeyWrap = false;
    skm = XSECCryptoSymmetricKey::MODE_NONE;
    taglen = 0;

    switch (kt) {

    case XSECCryptoKey::KEY_RSA_PUBLIC :
    case XSECCryptoKey::KEY_RSA_PAIR :
    case XSECCryptoKey::KEY_RSA_PRIVATE :
        keyOK = strEquals(uri, DSIGConstants::s_unicodeStrURIRSA_1_5) ||
            strEquals(uri, DSIGConstants::s_unicodeStrURIRSA_OAEP_MGFP1) ||
            strEquals(uri, DSIGConstants::s_unicodeStrURIRSA_OAEP);
        break;

    case XSECCryptoKey::KEY_SYMMETRIC :

        keySymmetric = (XSECCryptoSymmetricKey*) key;
        if (keySymmetric != NULL) {
            skt = keySymmetric->getSymmetricKeyType();

            switch (skt) {

            case XSECCryptoSymmetricKey::KEY_3DES_192 :
                if (strEquals(uri, DSIGConstants::s_unicodeStrURIKW_3DES)) {
                    keyOK = true;
                    isSymmetricKeyWrap = true;
                    skm = XSECCryptoSymmetricKey::MODE_CBC;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURI3DES_CBC)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_CBC;
                }
                break;

            case XSECCryptoSymmetricKey::KEY_AES_128 :
                if (strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES128) || strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES128_PAD)) {
                    keyOK = true;
                    isSymmetricKeyWrap = true;
                    skm = XSECCryptoSymmetricKey::MODE_ECB;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES128_CBC)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_CBC;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES128_GCM)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_GCM;
                    taglen = 16;
                }
                break;

            case XSECCryptoSymmetricKey::KEY_AES_192 :
                if (strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES192) || strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES192_PAD)) {
                    keyOK = true;
                    isSymmetricKeyWrap = true;
                    skm = XSECCryptoSymmetricKey::MODE_ECB;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES192_CBC)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_CBC;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES192_GCM)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_GCM;
                    taglen = 16;
                }
                break;

            case XSECCryptoSymmetricKey::KEY_AES_256 :
                if (strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES256) || strEquals(uri, DSIGConstants::s_unicodeStrURIKW_AES256_PAD)) {
                    keyOK = true;
                    isSymmetricKeyWrap = true;
                    skm = XSECCryptoSymmetricKey::MODE_ECB;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES256_CBC)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_CBC;
                }
                else if (strEquals(uri, DSIGConstants::s_unicodeStrURIAES256_GCM)) {
                    keyOK = true;
                    skm = XSECCryptoSymmetricKey::MODE_GCM;
                    taglen = 16;
                }
                break;

            default:
                break;
            }
        }
        break;

    default:
         break;
    }

    if (keyOK == false) {
        throw XSECException(XSECException::CipherError,
            "XENCAlgorithmHandlerDefault::mapURIToKey - key inappropriate for URI");
    }
}