Esempio n. 1
0
        protected new void ProcessCounterSignatures()
        {
            if (CounterSignerList.Count() != 0)
            {
                if (CounterSignerList.Count() == 1)
                {
                    AddAttribute(HeaderKeys.CounterSignature, CounterSignerList[0].EncodeToCBORObject(ProtectedBytes, RgbEncrypted), UNPROTECTED);
                }
                else
                {
                    CBORObject list = CBORObject.NewArray();
                    foreach (CounterSignature sig in CounterSignerList)
                    {
                        list.Add(sig.EncodeToCBORObject(ProtectedBytes, RgbEncrypted));
                    }
                    AddAttribute(HeaderKeys.CounterSignature, list, UNPROTECTED);
                }
            }

            if (CounterSigner1 != null)
            {
                AddAttribute(HeaderKeys.CounterSignature0, CounterSigner1.EncodeToCBORObject(ProtectedBytes, RgbEncrypted), UNPROTECTED);
            }
        }
Esempio n. 2
0
        public override CBORObject Encode()
        {
            CBORObject obj;

            byte[] rgbProtected;

            obj = CBORObject.NewArray();

            if ((ProtectedMap != null) && (ProtectedMap.Count > 0))
            {
                rgbProtected = ProtectedMap.EncodeToBytes();
                obj.Add(rgbProtected);
            }
            else
            {
                rgbProtected = new byte[0];
                obj.Add(rgbProtected);
            }

            if (CounterSignerList.Count() != 0)
            {
                if (CounterSignerList.Count() == 1)
                {
                    AddAttribute(HeaderKeys.CounterSignature, CounterSignerList[0].EncodeToCBORObject(rgbProtected, rgbContent), UNPROTECTED);
                }
                else
                {
                    foreach (CounterSignature sig in CounterSignerList)
                    {
                        sig.EncodeToCBORObject(rgbProtected, rgbContent);
                    }
                }
            }

            if (CounterSigner1 != null)
            {
                AddAttribute(HeaderKeys.CounterSignature0, CounterSigner1.EncodeToCBORObject(rgbProtected, rgbContent), UNPROTECTED);
            }

            if ((UnprotectedMap == null) || (UnprotectedMap.Count == 0))
            {
                obj.Add(CBORObject.NewMap());
            }
            else
            {
                obj.Add(UnprotectedMap);  // Add unprotected attributes
            }
            obj.Add(rgbContent);

            if ((signerList.Count == 1) && !m_forceArray)
            {
                CBORObject recipient = signerList[0].EncodeToCBORObject(obj[0].EncodeToBytes(), rgbContent);

                for (int i = 0; i < recipient.Count; i++)
                {
                    obj.Add(recipient[i]);
                }
            }
            else if (signerList.Count > 0)
            {
                CBORObject signers = CBORObject.NewArray();

                foreach (Signer key in signerList)
                {
                    signers.Add(key.EncodeToCBORObject(rgbProtected, rgbContent));
                }
                obj.Add(signers);
            }
            else
            {
                obj.Add(null);      // No recipients - set to null
            }
            return(obj);
        }