예제 #1
0
        public void _04_BoolAttributeTest()
        {
            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }
예제 #2
0
        public void _04_BoolAttributeTest()
        {
            Helpers.CheckPlatform();

            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == NativeLongUtils.ConvertFromCKA(CKA.CKA_TOKEN));
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }
        public void _04_BoolAttributeTest()
        {
            if (Platform.UnmanagedLongSize != 8 || Platform.StructPackingSize != 0)
            {
                Assert.Inconclusive("Test cannot be executed on this platform");
            }

            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }
예제 #4
0
        public static void GetAttributeNameAndValue(ObjectAttribute objectAttribute, out string name, out string value)
        {
            if (objectAttribute == null)
            {
                throw new ArgumentNullException("objectAttribute");
            }

            string tmpName  = null;
            string tmpValue = null;

            // Find attribute definition in configuration
            AttributeDefinition pkcs11Attribute = null;

            if (config.AttributeDefinitions.ContainsKey(objectAttribute.Type))
            {
                pkcs11Attribute = config.AttributeDefinitions[objectAttribute.Type];
            }

            // Determine attribute name
            if (pkcs11Attribute == null)
            {
                tmpName = string.Format("Unknown ({0})", objectAttribute.Type.ToString());
            }
            else
            {
                tmpName = pkcs11Attribute.Name;
            }

            // Determine attribute value
            if (pkcs11Attribute == null)
            {
                if (objectAttribute.CannotBeRead)
                {
                    tmpValue = "<unextractable>";
                }
                else
                {
                    tmpValue = BytesToHexString(objectAttribute.GetValueAsByteArray());
                }
            }
            else
            {
                if (objectAttribute.CannotBeRead)
                {
                    tmpValue = "<unextractable>";
                }
                else
                {
                    // TODO - More robust conversions
                    switch (pkcs11Attribute.Type)
                    {
                    case AttributeType.Bool:

                        tmpValue = objectAttribute.GetValueAsBool().ToString();

                        break;

                    case AttributeType.ByteArray:

                        tmpValue = BytesToHexString(objectAttribute.GetValueAsByteArray());

                        break;

                    case AttributeType.DateTime:

                        DateTime?dateTime = objectAttribute.GetValueAsDateTime();
                        tmpValue = (dateTime == null) ? null : dateTime.Value.ToShortDateString();

                        break;

                    case AttributeType.String:

                        tmpValue = objectAttribute.GetValueAsString();

                        break;

                    case AttributeType.ULong:

                        tmpValue = GetAttributeEnumValue(pkcs11Attribute, objectAttribute.GetValueAsUlong(), false);

                        break;

                    case AttributeType.AttributeArray:
                    case AttributeType.MechanismArray:
                    case AttributeType.ULongArray:

                        tmpValue = "<unsupported>";     // TODO

                        break;

                    default:

                        tmpValue = "<unknown>";

                        break;
                    }

                    if (string.IsNullOrEmpty(tmpValue))
                    {
                        tmpValue = "<empty>";
                    }
                }
            }

            // Set output parameters
            name  = tmpName;
            value = tmpValue;
        }
        public void _04_BoolAttributeTest()
        {
            bool value = true;

            // Create attribute with bool value
            using (ObjectAttribute attr = new ObjectAttribute(CKA.CKA_TOKEN, value))
            {
                Assert.IsTrue(attr.Type == (ulong)CKA.CKA_TOKEN);
                Assert.IsTrue(attr.GetValueAsBool() == value);
            }
        }