Example #1
0
        /**
         * return an Attribute object from the given object.
         *
         * @param o the object we want converted.
         * @exception ArgumentException if the object cannot be converted.
         */
        public static AttributePkcs GetInstance(
            object obj)
        {
            AttributePkcs attr = obj as AttributePkcs;

            if (obj == null || attr != null)
            {
                return(attr);
            }

            Asn1Sequence seq = obj as Asn1Sequence;

            if (seq != null)
            {
                return(new AttributePkcs(seq));
            }

            throw new ArgumentException("Unknown object in factory: " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(obj), "obj");
        }
Example #2
0
        private static void ValidateAttributes(Asn1Set attributes)
        {
            if (attributes == null)
            {
                return;
            }

            foreach (Asn1Encodable ae in attributes)
            {
                Asn1Object    obj  = ae.ToAsn1Object();
                AttributePkcs attr = AttributePkcs.GetInstance(obj);
                if (attr.AttrType.Equals(PkcsObjectIdentifiers.Pkcs9AtChallengePassword))
                {
                    if (attr.AttrValues.Count != 1)
                    {
                        throw new ArgumentException("challengePassword attribute must have one value");
                    }
                }
            }
        }