crypt32(4/6): Test encoding/decoding subject key identifier

Juan Lang juan.lang at gmail.com
Thu Aug 2 14:33:40 CDT 2007


--Juan
-------------- next part --------------
From 9168168288b721058e8b4f1e1a8c0d0cde1518de Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Thu, 2 Aug 2007 12:22:49 -0700
Subject: [PATCH] Test encoding/decoding subject key identifier
---
 dlls/crypt32/tests/encode.c |   70 +++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/dlls/crypt32/tests/encode.c b/dlls/crypt32/tests/encode.c
index a9efd22..282cdb2 100644
--- a/dlls/crypt32/tests/encode.c
+++ b/dlls/crypt32/tests/encode.c
@@ -1773,13 +1773,13 @@ struct encodedOctets
 };
 
 static const unsigned char bin46[] = { 'h','i',0 };
-static const unsigned char bin47[] = { 0x04,0x02,'h','i',0 };
+static const unsigned char bin47[] = { 0x04,0x02,'h','i' };
 static const unsigned char bin48[] = {
      's','o','m','e','l','o','n','g',0xff,'s','t','r','i','n','g',0 };
 static const unsigned char bin49[] = {
-     0x04,0x0f,'s','o','m','e','l','o','n','g',0xff,'s','t','r','i','n','g',0 };
+     0x04,0x0f,'s','o','m','e','l','o','n','g',0xff,'s','t','r','i','n','g' };
 static const unsigned char bin50[] = { 0 };
-static const unsigned char bin51[] = { 0x04,0x00,0 };
+static const unsigned char bin51[] = { 0x04,0x00 };
 
 static const struct encodedOctets octets[] = {
     { bin46, bin47 },
@@ -5353,6 +5353,68 @@ static void test_decodePKCSSignerInfo(DW
     }
 }
 
+static const BYTE encodedSerialNum[] = { 0x04,0x01,0x01 };
+
+static void test_encodeSubjectKeyIdentifier(DWORD dwEncoding)
+{
+    BOOL ret;
+    LPBYTE buf = NULL;
+    DWORD size = 0;
+    CRYPT_DATA_BLOB blob = { 0, NULL };
+
+    /* A subject key identifier just encodes as an octet string */
+    ret = CryptEncodeObjectEx(dwEncoding, szOID_SUBJECT_KEY_IDENTIFIER, &blob,
+     CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
+    if (ret)
+    {
+        ok(size == sizeof(bin51), "Unexpected size %d\n", size);
+        ok(!memcmp(buf, bin51, size), "Unexpected value\n");
+        LocalFree(buf);
+    }
+    blob.cbData = sizeof(serialNum);
+    blob.pbData = (LPBYTE)serialNum;
+    ret = CryptEncodeObjectEx(dwEncoding, szOID_SUBJECT_KEY_IDENTIFIER, &blob,
+     CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
+    if (ret)
+    {
+        ok(size == sizeof(encodedSerialNum), "Unexpected size %d\n", size);
+        ok(!memcmp(buf, encodedSerialNum, size), "Unexpected value\n");
+        LocalFree(buf);
+    }
+}
+
+static void test_decodeSubjectKeyIdentifier(DWORD dwEncoding)
+{
+    BOOL ret;
+    LPBYTE buf = NULL;
+    DWORD size = 0;
+
+    ret = CryptDecodeObjectEx(dwEncoding, szOID_SUBJECT_KEY_IDENTIFIER,
+     bin51, sizeof(bin51), CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
+    ok(ret, "CryptDecodeObjectEx failed: %x\n", GetLastError());
+    if (buf)
+    {
+        CRYPT_DATA_BLOB *blob = (CRYPT_DATA_BLOB *)buf;
+
+        ok(blob->cbData == 0, "Unexpected length %d\n", blob->cbData);
+        LocalFree(buf);
+    }
+    ret = CryptDecodeObjectEx(dwEncoding, szOID_SUBJECT_KEY_IDENTIFIER,
+     encodedSerialNum, sizeof(encodedSerialNum), CRYPT_DECODE_ALLOC_FLAG, NULL,
+     (BYTE *)&buf, &size);
+    ok(ret, "CryptDecodeObjectEx failed: %x\n", GetLastError());
+    if (buf)
+    {
+        CRYPT_DATA_BLOB *blob = (CRYPT_DATA_BLOB *)buf;
+
+        ok(blob->cbData == sizeof(serialNum), "Unexpected length %d\n",
+         blob->cbData);
+        ok(!memcmp(blob->pbData, serialNum, sizeof(serialNum)),
+         "Unexpected value\n");
+        LocalFree(buf);
+    }
+}
+
 /* Free *pInfo with HeapFree */
 static void testExportPublicKey(HCRYPTPROV csp, PCERT_PUBLIC_KEY_INFO *pInfo)
 {
@@ -5568,6 +5630,8 @@ START_TEST(encode)
         test_decodePKCSAttributes(encodings[i]);
         test_encodePKCSSignerInfo(encodings[i]);
         test_decodePKCSSignerInfo(encodings[i]);
+        test_encodeSubjectKeyIdentifier(encodings[i]);
+        test_decodeSubjectKeyIdentifier(encodings[i]);
     }
     testPortPublicKeyInfo();
 }
-- 
1.4.1


More information about the wine-patches mailing list