/// <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 )); }
private static Dictionary <string, string> TryParseExtraFields(byte[] signatureSnapshot) { Dictionary <string, string> extraFields = null; if (signatureSnapshot != null) { try { extraFields = SnapshotUtils.ParseSnapshot <Dictionary <string, string> >(signatureSnapshot); } catch (Exception) { } } return(extraFields); }
internal static RawSignedModel Generate( ICardCrypto cardCrypto, CardParams @params, DateTime createdAt) { ValidateGenerateParams(cardCrypto, @params); var details = new RawCardContent { Identity = @params.Identity, PublicKey = cardCrypto.ExportPublicKey(@params.PublicKey), Version = CardVersion, CreatedAt = createdAt, PreviousCardId = @params.PreviousCardId }; return(new RawSignedModel() { ContentSnapshot = SnapshotUtils.TakeSnapshot(details) }); }