]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Pem/CryptPem.c
Fix some typo and coding style issues in BaseCryptLib instances.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Pem / CryptPem.c
index 0b37adc33e81ab6c9716c791762dd394dabb716e..319ad59eccfe761f420fd9e75060de1617169ec5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   PEM (Privacy Enhanced Mail) Format Handler Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -36,7 +36,7 @@ PasswordCallback (
 {\r
   INTN  KeyLength;\r
 \r
-  ZeroMem ((VOID *)Buf, (UINTN)Size);\r
+  ZeroMem ((VOID *) Buf, (UINTN) Size);\r
   if (Key != NULL) {\r
     //\r
     // Duplicate key phrase directly.\r
@@ -60,8 +60,8 @@ PasswordCallback (
                            RSA private key component. Use RsaFree() function to free the\r
                            resource.\r
 \r
-  If PemData is NULL, then ASSERT().\r
-  If RsaContext is NULL, then ASSERT().\r
+  If PemData is NULL, then return FALSE.\r
+  If RsaContext is NULL, then return FALSE.\r
 \r
   @retval  TRUE   RSA Private Key was retrieved successfully.\r
   @retval  FALSE  Invalid PEM key data or incorrect password.\r
@@ -80,11 +80,11 @@ RsaGetPrivateKeyFromPem (
   BIO      *PemBio;\r
 \r
   //\r
-  // ASSERT if PemData is NULL or RsaContext is NULL.\r
+  // Check input parameters.\r
   //\r
-  ASSERT (PemData    != NULL);\r
-  ASSERT (RsaContext != NULL);\r
-  ASSERT (PemSize    <= INT_MAX);\r
+  if (PemData == NULL || RsaContext == NULL || PemSize > INT_MAX) {\r
+    return FALSE;\r
+  }\r
 \r
   Status = FALSE;\r
   PemBio = NULL;\r
@@ -93,16 +93,16 @@ RsaGetPrivateKeyFromPem (
   // Add possible block-cipher descriptor for PEM data decryption.\r
   // NOTE: Only support most popular ciphers (3DES, AES) for the encrypted PEM.\r
   //\r
-  EVP_add_cipher (EVP_des_ede3_cbc());\r
-  EVP_add_cipher (EVP_aes_128_cbc());\r
-  EVP_add_cipher (EVP_aes_192_cbc());\r
-  EVP_add_cipher (EVP_aes_256_cbc());\r
+  EVP_add_cipher (EVP_des_ede3_cbc ());\r
+  EVP_add_cipher (EVP_aes_128_cbc ());\r
+  EVP_add_cipher (EVP_aes_192_cbc ());\r
+  EVP_add_cipher (EVP_aes_256_cbc ());\r
 \r
   //\r
   // Read encrypted PEM Data.\r
   //\r
   PemBio = BIO_new (BIO_s_mem ());\r
-  BIO_write (PemBio, PemData, (int)PemSize);\r
+  BIO_write (PemBio, PemData, (int) PemSize);\r
   if (PemBio == NULL) {\r
     goto _Exit;\r
   }\r
@@ -110,7 +110,7 @@ RsaGetPrivateKeyFromPem (
   //\r
   // Retrieve RSA Private Key from encrypted PEM data.\r
   //\r
-  *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *)&PasswordCallback, (void *)Password);\r
+  *RsaContext = PEM_read_bio_RSAPrivateKey (PemBio, NULL, (pem_password_cb *) &PasswordCallback, (void *) Password);\r
   if (*RsaContext != NULL) {\r
     Status = TRUE;\r
   }\r