Multi-line svn commit, see body.
authorScott Cantor <cantor.2@osu.edu>
Fri, 20 Apr 2007 03:16:22 +0000 (03:16 +0000)
committerScott Cantor <cantor.2@osu.edu>
Fri, 20 Apr 2007 03:16:22 +0000 (03:16 +0000)
Make structure members public.
Recalculate key size of generated encryption keys.

xmltooling/encryption/Encrypter.h
xmltooling/encryption/impl/Encrypter.cpp

index efe658a..86fe642 100644 (file)
@@ -64,7 +64,6 @@ namespace xmlencryption {
          * Structure to collect encryption requirements.
          */
         struct XMLTOOL_API EncryptionParams {
-            
             /**
              * Constructor.
              *
@@ -88,21 +87,18 @@ namespace xmlencryption {
             }
 
             ~EncryptionParams() {}
-        private:
+
             const XMLCh* m_algorithm;
             const unsigned char* m_keyBuffer;
             unsigned int m_keyBufferSize;
             const xmltooling::Credential* m_credential;
             bool m_compact;
-            
-            friend class Encrypter;
         };
         
         /**
          * Structure to collect key wrapping/transport requirements.
          */
         struct XMLTOOL_API KeyEncryptionParams {
-            
             /**
              * Constructor.
              * 
@@ -118,12 +114,10 @@ namespace xmlencryption {
             }
         
             ~KeyEncryptionParams() {}
-        private:
+
             const xmltooling::Credential& m_credential;
             const XMLCh* m_algorithm;
             const XMLCh* m_recipient;
-            
-            friend class Encrypter;
         };
     
         Encrypter() : m_cipher(NULL) {}
index 95d5da7..ae184e9 100644 (file)
@@ -49,7 +49,7 @@ void Encrypter::checkParams(EncryptionParams& encParams, KeyEncryptionParams* ke
             if (kencParams)
                 throw EncryptionException("Generating EncryptedKey inline requires the encryption key in raw form.");
         }
-        else if (!encParams.m_credential) {
+        else {
             if (!kencParams)
                 throw EncryptionException("Using a generated encryption key requires a KeyEncryptionParams object.");
 
@@ -79,6 +79,21 @@ void Encrypter::checkParams(EncryptionParams& encParams, KeyEncryptionParams* ke
 
         if (!key)
             throw EncryptionException("Unable to build wrapper for key, unknown algorithm?");
+        // Overwrite the length if known.
+        switch (static_cast<XSECCryptoSymmetricKey*>(key)->getSymmetricKeyType()) {
+            case XSECCryptoSymmetricKey::KEY_3DES_192:
+                encParams.m_keyBufferSize = 192/8;
+                break;
+            case XSECCryptoSymmetricKey::KEY_AES_128:
+                encParams.m_keyBufferSize = 128/8;
+                break;
+            case XSECCryptoSymmetricKey::KEY_AES_192:
+                encParams.m_keyBufferSize = 192/8;
+                break;
+            case XSECCryptoSymmetricKey::KEY_AES_256:
+                encParams.m_keyBufferSize = 256/8;
+                break;
+        }
         // Set the encryption key.
         m_cipher->setKey(key);
     }
@@ -230,7 +245,9 @@ EncryptedData* Encrypter::decorateAndUnmarshall(EncryptionParams& encParams, Key
     return xmlEncData;
 }
 
-EncryptedKey* Encrypter::encryptKey(const unsigned char* keyBuffer, unsigned int keyBufferSize, KeyEncryptionParams& kencParams, bool compact)
+EncryptedKey* Encrypter::encryptKey(
+    const unsigned char* keyBuffer, unsigned int keyBufferSize, KeyEncryptionParams& kencParams, bool compact
+    )
 {
     // Get a fresh cipher object and document.