Exemplo n.º 1
0
 /**
  * create a sequence containing a vector of objects.
  */
 public DerSequence(
     Asn1EncodableVector v)
     : base(v.Count)
 {
     foreach (Asn1Encodable ae in v)
     {
         AddObject(ae);
     }
 }
 public static Asn1EncodableVector FromEnumerable(
     IEnumerable e)
 {
     Asn1EncodableVector v = new Asn1EncodableVector();
     foreach (Asn1Encodable obj in e)
     {
         v.Add(obj);
     }
     return v;
 }
Exemplo n.º 3
0
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(p, g);

            if (this.l != null)
            {
                v.Add(l);
            }

            return new DerSequence(v);
        }
Exemplo n.º 4
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * IDEA-CBCPar ::= Sequence {
         *                      iv    OCTET STRING OPTIONAL -- exactly 8 octets
         *                  }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            if (iv != null)
            {
                v.Add(iv);
            }

            return new DerSequence(v);
        }
Exemplo n.º 5
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * ContentInfo ::= Sequence {
         *          contentType ContentType,
         *          content
         *          [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(contentType);

            if (content != null)
            {
                v.Add(new BerTaggedObject(0, content));
            }

            return new BerSequence(v);
        }
        public AttributeTable(
            Asn1EncodableVector v)
        {
            this.attributes = Platform.CreateHashtable(v.Count);

            for (int i = 0; i != v.Count; i++)
            {
                AttributeX509 a = AttributeX509.GetInstance(v[i]);

                attributes.Add(a.AttrType, a);
            }
        }
Exemplo n.º 7
0
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                new DerInteger(3), contentInfo);

            if (macData != null)
            {
                v.Add(macData);
            }

            return new BerSequence(v);
        }
Exemplo n.º 8
0
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                bagID, new DerTaggedObject(0, bagValue));

            if (bagAttributes != null)
            {
                v.Add(bagAttributes);
            }

            return new DerSequence(v);
        }
        public AttributeTable(
            Asn1EncodableVector v)
        {
            this.attributes = Platform.CreateHashtable(v.Count);

            foreach (Asn1Encodable o in v)
            {
                Attribute a = Attribute.GetInstance(o);

                AddAttribute(a);
            }
        }
Exemplo n.º 10
0
        internal DerSet(
            Asn1EncodableVector	v,
            bool				needsSorting)
            : base(v.Count)
        {
            foreach (Asn1Encodable o in v)
            {
                AddObject(o);
            }

            if (needsSorting)
            {
                Sort();
            }
        }
Exemplo n.º 11
0
        public DerExternal(
            Asn1EncodableVector vector)
        {
            int offset = 0;
            Asn1Object enc = GetObjFromVector(vector, offset);
            if (enc is DerObjectIdentifier)
            {
                directReference = (DerObjectIdentifier)enc;
                offset++;
                enc = GetObjFromVector(vector, offset);
            }
            if (enc is DerInteger)
            {
                indirectReference = (DerInteger) enc;
                offset++;
                enc = GetObjFromVector(vector, offset);
            }
            if (!(enc is DerTaggedObject))
            {
                dataValueDescriptor = (Asn1Object) enc;
                offset++;
                enc = GetObjFromVector(vector, offset);
            }
            if (!(enc is DerTaggedObject))
            {
                throw new InvalidOperationException(
                    "No tagged object found in vector. Structure doesn't seem to be of type External");
            }

            if (vector.Count != offset + 1)
                throw new ArgumentException("input vector too large", "vector");

            if (!(enc is DerTaggedObject))
                throw new ArgumentException("No tagged object found in vector. Structure doesn't seem to be of type External", "vector");

            DerTaggedObject obj = (DerTaggedObject)enc;

            // Use property accessor to include check on value
            Encoding = obj.TagNo;

            if (encoding < 0 || encoding > 2)
                throw new InvalidOperationException("invalid encoding value");

            externalContent = obj.GetObject();
        }
        public DerApplicationSpecific(
            int					tagNo,
            Asn1EncodableVector	vec)
        {
            this.tag = tagNo;
            this.isConstructed = true;
            MemoryStream bOut = new MemoryStream();

            for (int i = 0; i != vec.Count; i++)
            {
                try
                {
                    byte[] bs = vec[i].GetDerEncoded();
                    bOut.Write(bs, 0, bs.Length);
                }
                catch (IOException e)
                {
                    throw new InvalidOperationException("malformed object", e);
                }
            }
            this.octets = bOut.ToArray();
        }
        public ECPrivateKeyStructure(
            BigInteger		key,
            DerBitString	publicKey,
            Asn1Encodable	parameters)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            Asn1EncodableVector v = new Asn1EncodableVector(
                new DerInteger(1),
                new DerOctetString(key.ToByteArrayUnsigned()));

            if (parameters != null)
            {
                v.Add(new DerTaggedObject(true, 0, parameters));
            }

            if (publicKey != null)
            {
                v.Add(new DerTaggedObject(true, 1, publicKey));
            }

            this.seq = new DerSequence(v);
        }
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * EncryptedContentInfo ::= Sequence {
         *     contentType ContentType,
         *     contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
         *     encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL
         * }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                contentType, contentEncryptionAlgorithm);

            if (encryptedContent != null)
            {
                v.Add(new BerTaggedObject(false, 0, encryptedContent));
            }

            return new BerSequence(v);
        }
Exemplo n.º 15
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         *  SignerInfo ::= Sequence {
         *      version Version,
         *      issuerAndSerialNumber IssuerAndSerialNumber,
         *      digestAlgorithm DigestAlgorithmIdentifier,
         *      authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
         *      digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
         *      encryptedDigest EncryptedDigest,
         *      unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
         *  }
         *
         *  EncryptedDigest ::= OCTET STRING
         *
         *  DigestAlgorithmIdentifier ::= AlgorithmIdentifier
         *
         *  DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                version, issuerAndSerialNumber, digAlgorithm);

            if (authenticatedAttributes != null)
            {
                v.Add(new DerTaggedObject(false, 0, authenticatedAttributes));
            }

            v.Add(digEncryptionAlgorithm, encryptedDigest);

            if (unauthenticatedAttributes != null)
            {
                v.Add(new DerTaggedObject(false, 1, unauthenticatedAttributes));
            }

            return new DerSequence(v);
        }
Exemplo n.º 16
0
        /**
        * <pre>
        *   SignerLocation ::= SEQUENCE {
        *       countryName        [0] DirectoryString OPTIONAL,
        *       localityName       [1] DirectoryString OPTIONAL,
        *       postalAddress      [2] PostalAddress OPTIONAL }
        *
        *   PostalAddress ::= SEQUENCE SIZE(1..6) OF DirectoryString
        *
        *   DirectoryString ::= CHOICE {
        *         teletexString           TeletexString (SIZE (1..MAX)),
        *         printableString         PrintableString (SIZE (1..MAX)),
        *         universalString         UniversalString (SIZE (1..MAX)),
        *         utf8String              UTF8String (SIZE (1.. MAX)),
        *         bmpString               BMPString (SIZE (1..MAX)) }
        * </pre>
        */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            if (countryName != null)
            {
                v.Add(new DerTaggedObject(true, 0, countryName));
            }

            if (localityName != null)
            {
                v.Add(new DerTaggedObject(true, 1, localityName));
            }

            if (postalAddress != null)
            {
                v.Add(new DerTaggedObject(true, 2, postalAddress));
            }

            return new DerSequence(v);
        }
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * BasicOcspResponse       ::= Sequence {
         *      tbsResponseData      ResponseData,
         *      signatureAlgorithm   AlgorithmIdentifier,
         *      signature            BIT STRING,
         *      certs                [0] EXPLICIT Sequence OF Certificate OPTIONAL }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                tbsResponseData, signatureAlgorithm, signature);

            if (certs != null)
            {
                v.Add(new DerTaggedObject(true, 0, certs));
            }

            return new DerSequence(v);
        }
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * BasicConstraints := Sequence {
         *    cA                  Boolean DEFAULT FALSE,
         *    pathLenConstraint   Integer (0..MAX) OPTIONAL
         * }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            if (cA != null)
            {
                v.Add(cA);
            }

            if (pathLenConstraint != null)  // yes some people actually do this when cA is false...
            {
                v.Add(pathLenConstraint);
            }

            return new DerSequence(v);
        }
Exemplo n.º 19
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * OcspResponse ::= Sequence {
         *     responseStatus         OcspResponseStatus,
         *     responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(responseStatus);

            if (responseBytes != null)
            {
                v.Add(new DerTaggedObject(true, 0, responseBytes));
            }

            return new DerSequence(v);
        }
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                publicKeyParamSet, digestParamSet);

            if (encryptionParamSet != null)
            {
                v.Add(encryptionParamSet);
            }

            return new DerSequence(v);
        }
Exemplo n.º 21
0
 public static DerSet FromVector(
     Asn1EncodableVector v)
 {
     return v.Count < 1 ? Empty : new DerSet(v);
 }
Exemplo n.º 22
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * Request         ::=     Sequence {
         *     reqCert                     CertID,
         *     singleRequestExtensions     [0] EXPLICIT Extensions OPTIONAL }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(reqCert);

            if (singleRequestExtensions != null)
            {
                v.Add(new DerTaggedObject(true, 0, singleRequestExtensions));
            }

            return new DerSequence(v);
        }
Exemplo n.º 23
0
 /**
  * @param v - a vector of objects making up the set.
  */
 public DerSet(
     Asn1EncodableVector v)
     : this(v, true)
 {
 }
Exemplo n.º 24
0
        internal Asn1EncodableVector BuildEncodableVector()
        {
            Asn1EncodableVector v = new Asn1EncodableVector();

            Asn1Object o;
            while ((o = ReadObject()) != null)
            {
                v.Add(o);
            }

            return v;
        }
Exemplo n.º 25
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         *  SingleResponse ::= Sequence {
         *          certID                       CertID,
         *          certStatus                   CertStatus,
         *          thisUpdate                   GeneralizedTime,
         *          nextUpdate         [0]       EXPLICIT GeneralizedTime OPTIONAL,
         *          singleExtensions   [1]       EXPLICIT Extensions OPTIONAL }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                certID, certStatus, thisUpdate);

            if (nextUpdate != null)
            {
                v.Add(new DerTaggedObject(true, 0, nextUpdate));
            }

            if (singleExtensions != null)
            {
                v.Add(new DerTaggedObject(true, 1, singleExtensions));
            }

            return new DerSequence(v);
        }
        /**
        * <pre>
        * CommitmentTypeIndication ::= SEQUENCE {
        *      commitmentTypeId   CommitmentTypeIdentifier,
        *      commitmentTypeQualifier   SEQUENCE SIZE (1..MAX) OF
        *              CommitmentTypeQualifier OPTIONAL }
        * </pre>
        */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(commitmentTypeId);

            if (commitmentTypeQualifier != null)
            {
                v.Add(commitmentTypeQualifier);
            }

            return new DerSequence(v);
        }
Exemplo n.º 27
0
 /**
  * Produce an object suitable for an Asn1OutputStream.
  * <pre>
  * KekIdentifier ::= Sequence {
  *     keyIdentifier OCTET STRING,
  *     date GeneralizedTime OPTIONAL,
  *     other OtherKeyAttribute OPTIONAL
  * }
  * </pre>
  */
 public override Asn1Object ToAsn1Object()
 {
     Asn1EncodableVector v = new Asn1EncodableVector(keyIdentifier);
     v.AddOptional(date, other);
     return new DerSequence(v);
 }
Exemplo n.º 28
0
 internal static DerSet FromVector(
     Asn1EncodableVector	v,
     bool				needsSorting)
 {
     return v.Count < 1 ? Empty : new DerSet(v, needsSorting);
 }
Exemplo n.º 29
0
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * SignedData ::= Sequence {
         *     version CMSVersion,
         *     digestAlgorithms DigestAlgorithmIdentifiers,
         *     encapContentInfo EncapsulatedContentInfo,
         *     certificates [0] IMPLICIT CertificateSet OPTIONAL,
         *     crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
         *     signerInfos SignerInfos
         *   }
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                version, digestAlgorithms, contentInfo);

            if (certificates != null)
            {
                if (certsBer)
                {
                    v.Add(new BerTaggedObject(false, 0, certificates));
                }
                else
                {
                    v.Add(new DerTaggedObject(false, 0, certificates));
                }
            }

            if (crls != null)
            {
                if (crlsBer)
                {
                    v.Add(new BerTaggedObject(false, 1, crls));
                }
                else
                {
                    v.Add(new DerTaggedObject(false, 1, crls));
                }
            }

            v.Add(signerInfos);

            return new BerSequence(v);
        }
        /**
         * Produce an object suitable for an Asn1OutputStream.
         * <pre>
         * KeyAgreeRecipientInfo ::= Sequence {
         *     version CMSVersion,  -- always set to 3
         *     originator [0] EXPLICIT OriginatorIdentifierOrKey,
         *     ukm [1] EXPLICIT UserKeyingMaterial OPTIONAL,
         *     keyEncryptionAlgorithm KeyEncryptionAlgorithmIdentifier,
         *     recipientEncryptedKeys RecipientEncryptedKeys
         * }
         *
         * UserKeyingMaterial ::= OCTET STRING
         * </pre>
         */
        public override Asn1Object ToAsn1Object()
        {
            Asn1EncodableVector v = new Asn1EncodableVector(
                version, new DerTaggedObject(true, 0, originator));

            if (ukm != null)
            {
                v.Add(new DerTaggedObject(true, 1, ukm));
            }

            v.Add(keyEncryptionAlgorithm, recipientEncryptedKeys);

            return new DerSequence(v);
        }