MYCryptoTest.m
changeset 14 3af1d1c0ceb5
parent 13 6fd9177eb6da
child 16 c409dbc4f068
     1.1 --- a/MYCryptoTest.m	Sun Apr 19 00:01:41 2009 -0700
     1.2 +++ b/MYCryptoTest.m	Sun Apr 19 21:19:35 2009 -0700
     1.3 @@ -207,6 +207,7 @@
     1.4  }
     1.5  
     1.6  
     1.7 +#if !TARGET_OS_IPHONE
     1.8  TestCase(MYSymmetricKeyPassphrase) {
     1.9      Log(@"Prompting for raw passphrase --");
    1.10      NSString *rawPassphrase = [MYSymmetricKey promptForPassphraseWithAlertTitle: @"Raw Passphrase Test" 
    1.11 @@ -243,6 +244,7 @@
    1.12      decrypted = [key2 decryptData: encrypted];
    1.13      CAssertEqual(decrypted, cleartext);
    1.14  }
    1.15 +#endif
    1.16  
    1.17  
    1.18  #pragma mark -
    1.19 @@ -265,6 +267,7 @@
    1.20      CAssertEqual(pair.publicKeyDigest, pubKeyDigest);
    1.21      
    1.22      Log(@"SHA1 of pub key = %@", pubKeyData.my_SHA1Digest.asData);
    1.23 +    CAssertEqual(pubKeyData.my_SHA1Digest,pubKeyDigest);
    1.24      
    1.25      // Let's sign data:
    1.26      NSData *data = [@"This is a test. This is only a test!" dataUsingEncoding: NSUTF8StringEncoding];
    1.27 @@ -296,9 +299,13 @@
    1.28  }
    1.29  
    1.30  
    1.31 -static void testWrapSessionKey( MYPrivateKey *privateKey ) {
    1.32 +static void TestWrapSessionKey( MYPrivateKey *privateKey ) {
    1.33 +#if !TARGET_OS_IPHONE
    1.34      MYSymmetricKey *sessionKey = [MYSymmetricKey generateSymmetricKeyOfSize: 128 algorithm:kCCAlgorithmAES128];
    1.35      CAssert(sessionKey);
    1.36 +    NSData *cleartext = [@"This is a test. This is only a test." dataUsingEncoding: NSUTF8StringEncoding];
    1.37 +    NSData *encrypted = [sessionKey encryptData: cleartext];
    1.38 +
    1.39      Log(@"Wrapping session key %@, %@", sessionKey, sessionKey.keyData);
    1.40      NSData *wrapped = [privateKey.publicKey wrapSessionKey: sessionKey];
    1.41      Log(@"Wrapped session key = %u bytes: %@", wrapped.length,wrapped);
    1.42 @@ -309,7 +316,14 @@
    1.43                                                       sizeInBits: 128];
    1.44      Log(@"Unwrapped session key = %@, %@", unwrappedKey, unwrappedKey.keyData);
    1.45      CAssert(unwrappedKey);
    1.46 +    CAssertEq(unwrappedKey.algorithm, sessionKey.algorithm);
    1.47 +    CAssertEq(unwrappedKey.keySizeInBits, sessionKey.keySizeInBits);
    1.48      CAssertEqual(unwrappedKey.keyData, sessionKey.keyData);
    1.49 +
    1.50 +    Log(@"Verifying that unwrapped key works");
    1.51 +    NSData *decrypted = [unwrappedKey decryptData: encrypted];
    1.52 +    CAssertEqual(decrypted, cleartext);
    1.53 +#endif
    1.54  }
    1.55  
    1.56  
    1.57 @@ -323,7 +337,7 @@
    1.58      
    1.59      @try{
    1.60          TestUseKeyPair(pair);
    1.61 -        testWrapSessionKey(pair);
    1.62 +        TestWrapSessionKey(pair);
    1.63          
    1.64          [pair setName: @"Test KeyPair Label"];
    1.65          CAssertEqual(pair.name, @"Test KeyPair Label");