예제 #1
0
        /// <summary>
        /// Loads <see cref="Card"/> from the specified <see cref="RawSignedModel"/>.
        /// </summary>
        /// <param name="cardCrypto">an instance of <see cref="ICardCrypto"/>.</param>
        /// <param name="rawSignedModel">an instance of <see cref="RawSignedModel"/> to get
        /// <see cref="Card"/> from.</param>
        /// <param name="isOutdated"></param>
        /// <returns>Loaded instance of <see cref="Card"/>.</returns>
        public static Card Parse(ICardCrypto cardCrypto, RawSignedModel rawSignedModel, bool isOutdated = false)
        {
            ValidateParams(cardCrypto, rawSignedModel);

            var rawCardContent = SnapshotUtils.ParseSnapshot <RawCardContent>(rawSignedModel.ContentSnapshot);

            var signatures = new List <CardSignature>();

            if (rawSignedModel.Signatures != null)
            {
                foreach (var s in rawSignedModel.Signatures)
                {
                    var cardSignature = new CardSignature
                    {
                        Signer      = s.Signer,
                        Signature   = s.Signature,
                        ExtraFields = TryParseExtraFields(s.Snapshot),
                        Snapshot    = s.Snapshot
                    };
                    signatures.Add(cardSignature);
                }
            }

            return(new Card(
                       GenerateCardId(cardCrypto, rawSignedModel.ContentSnapshot),
                       rawCardContent.Identity,
                       cardCrypto.ImportPublicKey(rawCardContent.PublicKey),
                       rawCardContent.Version,
                       rawCardContent.CreatedAt,
                       signatures,
                       rawCardContent.PreviousCardId,
                       rawSignedModel.ContentSnapshot,
                       isOutdated
                       ));
        }
        public void Validate_ShouldReturnSuccess_IfSpecifiedWhitelistSignersAreValid()
        {
            var crypto    = Substitute.For <ICardCrypto>();
            var validator = new VirgilCardVerifier(crypto);

            validator.VerifySelfSignature   = false;
            validator.VerifyVirgilSignature = false;
            var signer          = this.faker.VerifierCredentialAndSignature("exta");
            var signerInfo      = signer.Item1;
            var signerSignature = new CardSignature()
            {
                Snapshot  = signer.Item2.Snapshot,
                Signer    = signer.Item2.Signer,
                Signature = signer.Item2.Signature
            };
            //C signer.Item2;}
            var card = this.faker.Card(false, false, new List <CardSignature> {
                signerSignature
            });

            crypto.VerifySignature(
                signerSignature.Signature,
                card.ContentSnapshot,
                Arg.Any <IPublicKey>()).Returns(true);

            var whiteList = new Whitelist
            {
                VerifiersCredentials = new List <VerifierCredentials>()
                {
                    { signerInfo }
                }
            };

            validator.Whitelists = new List <Whitelist>()
            {
                whiteList
            };
            var result = validator.VerifyCard(card);

            Assert.IsTrue(result);
        }