/// <summary> /// Add a recipient entry to the recipient list. /// </summary> /// <param name="Recipient"></param> public void Add(Recipient Recipient) { Recipients = Recipients == null ? new List<Recipient>() : Recipients; Recipients.Add(Recipient); }
/// <summary> /// Add an entry for the specified key to the recipient list. /// </summary> /// <param name="EncryptionKey">The encryption key to create the /// entry for.</param> public void Add(KeyPair EncryptionKey) { var Recipient = new Recipient(EncryptionKey); //Trace.WriteLine("Create blob for {0}", EncryptionKey.UDF); Recipient.EncryptedKey = EncryptKey(EncryptionKey); //Trace.WriteHex("Created", Recipient.EncryptedKey); Recipient.Header = new Header(); Recipient.Header.kid = EncryptionKey.UDF; Add(Recipient); return; }
/// <summary> /// Having read a tag, process the corresponding value data. /// </summary> /// <param name="JSONReader"></param> /// <param name="Tag"></param> public override void DeserializeToken (JSONReader JSONReader, string Tag) { switch (Tag) { case "protected" : { Protected = JSONReader.ReadBinary (); break; } case "unprotected" : { Unprotected = JSONReader.ReadBinary (); break; } case "iv" : { IV = JSONReader.ReadBinary (); break; } case "ciphertext" : { CipherText = JSONReader.ReadBinary (); break; } case "tag" : { JTag = JSONReader.ReadBinary (); break; } case "aad" : { AdditionalAuthenticatedData = JSONReader.ReadBinary (); break; } case "recipients" : { // Have a sequence of values bool _Going = JSONReader.StartArray (); Recipients = new List <Recipient> (); while (_Going) { // an untagged structure. var _Item = new Recipient (JSONReader); Recipients.Add (_Item); _Going = JSONReader.NextArray (); } break; } default : { break; } } // check up that all the required elements are present }
/// <summary> /// Construct an instance from the specified tagged JSONReader stream. /// </summary> public static void Deserialize(JSONReader JSONReader, out JSONObject Out) { JSONReader.StartObject (); if (JSONReader.EOR) { Out = null; return; } string token = JSONReader.ReadToken (); Out = null; switch (token) { case "JoseWebSignature" : { var Result = new JoseWebSignature (); Result.Deserialize (JSONReader); Out = Result; break; } case "JoseWebEncryption" : { var Result = new JoseWebEncryption (); Result.Deserialize (JSONReader); Out = Result; break; } case "Signed" : { var Result = new Signed (); Result.Deserialize (JSONReader); Out = Result; break; } case "Encrypted" : { var Result = new Encrypted (); Result.Deserialize (JSONReader); Out = Result; break; } case "KeyData" : { var Result = new KeyData (); Result.Deserialize (JSONReader); Out = Result; break; } case "Header" : { var Result = new Header (); Result.Deserialize (JSONReader); Out = Result; break; } case "Key" : { var Result = new Key (); Result.Deserialize (JSONReader); Out = Result; break; } case "Recipient" : { var Result = new Recipient (); Result.Deserialize (JSONReader); Out = Result; break; } case "PublicKeyRSA" : { var Result = new PublicKeyRSA (); Result.Deserialize (JSONReader); Out = Result; break; } case "PrivateKeyRSA" : { var Result = new PrivateKeyRSA (); Result.Deserialize (JSONReader); Out = Result; break; } default : { throw new Exception ("Not supported"); } } JSONReader.EndObject (); }
/// <summary> /// Deserialize a tagged stream /// </summary> /// <param name="JSONReader"></param> public static new Recipient FromTagged (JSONReader JSONReader) { Recipient Out = null; JSONReader.StartObject (); if (JSONReader.EOR) { return null; } string token = JSONReader.ReadToken (); switch (token) { case "Recipient" : { var Result = new Recipient (); Result.Deserialize (JSONReader); Out = Result; break; } default : { //Ignore the unknown data //throw new Exception ("Not supported"); break; } } JSONReader.EndObject (); return Out; }