Ejemplo n.º 1
0
        protected static P11Attribute AssignAttributeFromObj(Session session, uint hObj, P11Attribute attr)
        {
            uint hSession = session.HSession;

            Wrapper.Pkcs11Module pm = session.Module.P11Module;
            try
            {
                return(attr.Load(pm.GetAttributeValue(hSession, hObj, new CK_ATTRIBUTE[] { attr.CK_ATTRIBUTE })[0]));
            }
            catch
            {//TODO:sadece attribute not found handle et
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static P11Attribute GetAttribute(Session session, uint hObj, P11Attribute attr)
        {
            try
            {
                uint hSession           = session.HSession;
                Wrapper.Pkcs11Module pm = session.Module.P11Module;

                CK_ATTRIBUTE tmp = pm.GetAttributeValue(hSession, hObj, new CK_ATTRIBUTE[] { attr.CK_ATTRIBUTE })[0];
                P11Attribute p11 = attr.Clone().Load(tmp);
                p11.MetaData.IsPresent   = true;
                p11.MetaData.IsSensitive = false;
                return(p11);
            }
            catch (TokenException tex)
            {
                if (tex.ErrorCode == CKR.ATTRIBUTE_TYPE_INVALID ||
                    tex.ErrorCode == CKR.ATTRIBUTE_VALUE_INVALID)
                {
                    P11Attribute p11 = attr.Clone();
                    p11.MetaData.IsPresent   = false;
                    p11.MetaData.IsSensitive = false;
                    return(p11);
                }
                else if (tex.ErrorCode == CKR.ATTRIBUTE_SENSITIVE)
                {
                    P11Attribute p11 = attr.Clone();
                    p11.MetaData.IsPresent   = true;
                    p11.MetaData.IsSensitive = true;
                    return(p11);
                }
                else
                {
                    throw tex;
                }
            }
        }