Ejemplo n.º 1
0
        /**
         * Return possible empty collection with recipients matching the passed in RecipientID
         *
         * @param selector a recipient id to select against.
         * @return a collection of RecipientInformation objects.
         */
        public ICollection GetRecipients(
            RecipientID selector)
        {
            IList list = (IList)table[selector];

            return(list == null?Platform.CreateArrayList() : Platform.CreateArrayList(list));
        }
Ejemplo n.º 2
0
        /**
         * Return the first RecipientInformation object that matches the
         * passed in selector. Null if there are no matches.
         *
         * @param selector to identify a recipient
         * @return a single RecipientInformation object. Null if none matches.
         */
        public RecipientInformation GetFirstRecipient(
            RecipientID selector)
        {
            IList list = (IList)table[selector];

            return(list == null ? null : (RecipientInformation)list[0]);
        }
Ejemplo n.º 3
0
 internal KeyAgreeRecipientInformation(
     KeyAgreeRecipientInfo info,
     RecipientID rid,
     Asn1OctetString encryptedKey,
     CmsSecureReadable secureReadable)
     : base(info.KeyEncryptionAlgorithm, secureReadable)
 {
     this.info         = info;
     this.rid          = rid;
     this.encryptedKey = encryptedKey;
 }
Ejemplo n.º 4
0
        private readonly IDictionary table = Platform.CreateHashtable(); // Hashtable[RecipientID, ArrayList[RecipientInformation]]

        public RecipientInformationStore(
            ICollection recipientInfos)
        {
            foreach (RecipientInformation recipientInformation in recipientInfos)
            {
                RecipientID rid  = recipientInformation.RecipientID;
                IList       list = (IList)table[rid];

                if (list == null)
                {
                    table[rid] = list = Platform.CreateArrayList(1);
                }

                list.Add(recipientInformation);
            }

            this.all = Platform.CreateArrayList(recipientInfos);
        }
Ejemplo n.º 5
0
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            RecipientID id = obj as RecipientID;

            if (id == null)
            {
                return(false);
            }

            return(Arrays.AreEqual(keyIdentifier, id.keyIdentifier) &&
                   Arrays.AreEqual(SubjectKeyIdentifier, id.SubjectKeyIdentifier) &&
                   Platform.Equals(SerialNumber, id.SerialNumber) &&
                   IssuersMatch(Issuer, id.Issuer));
        }
Ejemplo n.º 6
0
        internal static void ReadRecipientInfo(IList infos, KeyAgreeRecipientInfo info,
                                               CmsSecureReadable secureReadable)
        {
            try
            {
                foreach (Asn1Encodable rek in info.RecipientEncryptedKeys)
                {
                    RecipientEncryptedKey id = RecipientEncryptedKey.GetInstance(rek.ToAsn1Object());

                    RecipientID rid = new RecipientID();

                    Asn1.Cms.KeyAgreeRecipientIdentifier karid = id.Identifier;

                    Asn1.Cms.IssuerAndSerialNumber iAndSN = karid.IssuerAndSerialNumber;
                    if (iAndSN != null)
                    {
                        rid.Issuer       = iAndSN.Name;
                        rid.SerialNumber = iAndSN.SerialNumber.Value;
                    }
                    else
                    {
                        Asn1.Cms.RecipientKeyIdentifier rKeyID = karid.RKeyID;

                        // Note: 'date' and 'other' fields of RecipientKeyIdentifier appear to be only informational

                        rid.SubjectKeyIdentifier = rKeyID.SubjectKeyIdentifier.GetOctets();
                    }

                    infos.Add(new KeyAgreeRecipientInformation(info, rid, id.EncryptedKey,
                                                               secureReadable));
                }
            }
            catch (IOException e)
            {
                throw new ArgumentException("invalid rid in KeyAgreeRecipientInformation", e);
            }
        }
Ejemplo n.º 7
0
 public RecipientInformation this[RecipientID selector]
 {
     get { return(GetFirstRecipient(selector)); }
 }