/// <summary> /// Reads a key previously written by <see cref="Write(ICKBinaryWriter, KeyBase)"/>. /// </summary> /// <param name="clock">The system clock.</param> /// <param name="r">The reader.</param> /// <returns>The key.</returns> public static KeyBase Read(ISystemClock clock, ICKBinaryReader r) { r.ReadByte(); return(r.ReadChar() switch { 'R' => new RSAKey(clock, r), 'S' => new SymmetricKey(clock, r), 'E' => new ECKey(clock, r), _ => throw new InvalidDataException("Invalid Key type."), });
/// <summary> /// Reads a <see cref="CKTraitContext"/> that has been previously written by <see cref="Write"/>. /// </summary> /// <param name="r">The binary reader to use.</param> public static CKTraitContext Read(ICKBinaryReader r) { byte vS = r.ReadByte(); bool shared = (vS & 128) != 0; bool withTags = (vS & 64) != 0; var name = shared ? r.ReadSharedString() : r.ReadString(); var sep = r.ReadChar(); var tagReader = withTags ? r : null; return(shared ? Bind(name, sep, tagReader) : new CKTraitContext(name, sep, false, tagReader)); }