public void _07_GetObjectAttributes()
        {
            Helpers.CheckPlatform();

            string uri = @"pkcs11:object=foo;type=private;id=%01%02%03";

            Pkcs11Uri pkcs11uri = new Pkcs11Uri(uri);

            CK_ATTRIBUTE[] attributes = null;
            Pkcs11UriUtils.GetObjectAttributes(pkcs11uri, out attributes);

            Assert.IsTrue(attributes != null);
            Assert.IsTrue(attributes.Length == 3);

            Assert.IsTrue(attributes[0].type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS));
            NativeULong ckaClass = 0;

            CkaUtils.ConvertValue(ref attributes[0], out ckaClass);
            Assert.IsTrue(ckaClass == NativeLongUtils.ConvertFromCKO(CKO.CKO_PRIVATE_KEY));

            Assert.IsTrue(attributes[1].type == NativeLongUtils.ConvertFromCKA(CKA.CKA_LABEL));
            string ckaLabel = null;

            CkaUtils.ConvertValue(ref attributes[1], out ckaLabel);
            Assert.IsTrue(ckaLabel == "foo");

            Assert.IsTrue(attributes[2].type == NativeLongUtils.ConvertFromCKA(CKA.CKA_ID));
            byte[] ckaId = null;
            CkaUtils.ConvertValue(ref attributes[2], out ckaId);
            Assert.IsTrue(Common.Helpers.ByteArraysMatch(ckaId, new byte[] { 0x01, 0x02, 0x03 }));
        }
Ejemplo n.º 2
0
        public void _02_UintAttributeTest()
        {
            Helpers.CheckPlatform();

            NativeULong originalValue = NativeLongUtils.ConvertFromCKO(CKO.CKO_DATA);
            // Create attribute with NativeULong value
            CK_ATTRIBUTE attr = CkaUtils.CreateAttribute(CKA.CKA_CLASS, originalValue);

            Assert.IsTrue(attr.type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS));
            Assert.IsTrue(attr.value != IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == NativeLongUtils.ConvertFromInt32(UnmanagedMemory.SizeOf(typeof(NativeULong))));

            NativeULong recoveredValue = 0;

            // Read the value of attribute
            CkaUtils.ConvertValue(ref attr, out recoveredValue);
            Assert.IsTrue(originalValue == recoveredValue);

            // Free attribute value
            UnmanagedMemory.Free(ref attr.value);
            attr.valueLen = 0;
            Assert.IsTrue(attr.type == NativeLongUtils.ConvertFromCKA(CKA.CKA_CLASS));
            Assert.IsTrue(attr.value == IntPtr.Zero);
            Assert.IsTrue(attr.valueLen == 0);
        }