static CKTraitContext Bind(string name, char separator, ICKBinaryReader tagReader) { CKTraitContext c, exists; lock ( _basicLock ) { c = exists = _allContexts.FirstOrDefault(x => x.Name == name); if (exists == null) { _allContexts.Add(c = new CKTraitContext(name, separator, true, tagReader)); } } if (exists != null) { if (exists.Separator != separator) { throw new InvalidOperationException($"CKTraitContext named '{name}' is already defined with the separator '{exists.Separator}', it cannot be redefined with the separator '{separator}'."); } if (tagReader != null) { int count = tagReader.ReadInt32(); while (--count >= 0) { c.FindOrCreateAtomicTrait(tagReader.ReadString(), true); } } } return(c); }
public DeserializerContext(ICKBinaryReader reader) { Version = reader.ReadNonNegativeSmallInt32(); Reader = reader; TraitContextPool = new CKBinaryReader.ObjectPool <CKTraitContext>(Reader); TraitPool = new CKBinaryReader.ObjectPool <CKTrait>(Reader); }
internal ECKey(ISystemClock clock, ICKBinaryReader r) : base(clock, r) { r.ReadByte(); Oid?curveName = HelperAndExtensions.ReadNullableOid(r); Debug.Assert(curveName != null); _parameters = new ECParameters() { Curve = ECCurve.CreateFromOid(curveName), D = ReadBytes(r), Q = new ECPoint() { X = ReadBytes(r), Y = ReadBytes(r) } }; if (r.ReadBoolean()) { _ecdh = ECDiffieHellman.Create(_parameters); } else { _ec = ECDsa.Create(_parameters); } JWKCurveName = GetJWKCurveName(_parameters.Curve.Oid);
CKTraitContext(string name, char separator, bool shared, ICKBinaryReader r) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentException(Core.Impl.CoreResources.ArgumentMustNotBeNullOrWhiteSpace, "uniqueName"); } Name = name.Normalize(); Separator = separator; if (!shared) { Monitor.Enter(_basicLock); } var found = _regexes.FirstOrDefault(reg => reg.Key[0] == separator); if (found.Key == null) { _separatorString = new String(separator, 1); string pattern = "(\\s*" + Regex.Escape(_separatorString) + "\\s*)+"; _canonize2 = new Regex(pattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant); _regexes.Add(new KeyValuePair <string, Regex>(_separatorString, _canonize2)); } else { _separatorString = found.Key; _canonize2 = found.Value; } if (!shared) { Monitor.Exit(_basicLock); } EmptyTrait = new CKTrait(this); if (r != null) { IEnumerable <KeyValuePair <string, CKTrait> > Read() { yield return(new KeyValuePair <string, CKTrait>(String.Empty, EmptyTrait)); int count = r.ReadInt32(); for (int i = 0; i < count; ++i) { var s = r.ReadString(); yield return(new KeyValuePair <string, CKTrait>(s, new CKTrait(this, s))); } } _tags = new ConcurrentDictionary <string, CKTrait>(Read(), StringComparer.Ordinal); } else { _tags = new ConcurrentDictionary <string, CKTrait>(StringComparer.Ordinal); _tags[String.Empty] = EmptyTrait; } EnumWithEmpty = new CKTrait[] { EmptyTrait }; _creationLock = new Object(); _independentIndex = shared ? 0 : Interlocked.Increment(ref _nextIndependentIndex); }
/// <summary> /// Initializes a new object pool reader. /// </summary> /// <param name="r">The reader. Must not be null.</param> public ObjectPool(ICKBinaryReader r) { if (r == null) { throw new ArgumentNullException(nameof(r)); } _objects = new List <T>(); _r = r; }
static byte[]? ReadBytes(ICKBinaryReader r) { int l = r.ReadSmallInt32(); if (l < 0) { return(null); } return(r.ReadBytes(l)); }
/// <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."), });
public KeyRequirement(ICKBinaryReader r) { r.ReadByte(); // Version. KeyType = r.ReadEnum <KeyType>(); Operations = r.ReadEnum <KeyOperations>(); KeySizeInBits = r.ReadNullableInt32( ); CurveName = HelperAndExtensions.ReadNullableOid(r); if (r.ReadBoolean()) { InitiatorAlgorithmName = r.ReadString(); } }
/// <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)); }
private protected KeyBase(ISystemClock clock, ICKBinaryReader r) { Clock = clock; r.ReadByte(); Kty = r.ReadEnum <KeyType>(); Kid = JsonEncodedText.Encode(r.ReadString()); Operations = r.ReadEnum <KeyOperations>(); CreationDate = r.ReadDateTime(); BestBefore = r.ReadDateTime(); MaxUseCount = r.ReadUInt32(); _oUseCount = r.ReadInt32(); }
/// <summary> /// Initializes a database from its serialized binary data. /// </summary> /// <param name="r">The reader to use.</param> public PackageDB(ICKBinaryReader r) { var ctx = new DeserializerContext(r); _instances = new InstanceStore(ctx); int nbFeeds = ctx.Reader.ReadNonNegativeSmallInt32(); _feeds = new Dictionary <string, PackageFeed>(nbFeeds); while (--nbFeeds >= 0) { var f = new PackageFeed(_instances, ctx); _feeds.Add(f.TypedName, f); } _lastUpdate = DateTime.UtcNow; }
internal RSAKey(ISystemClock clock, ICKBinaryReader r) : base(clock, r) { r.ReadByte(); _parameters = new RSAParameters() { D = ReadBytes(r), DP = ReadBytes(r), DQ = ReadBytes(r), InverseQ = ReadBytes(r), P = ReadBytes(r), Q = ReadBytes(r), Modulus = ReadBytes(r), Exponent = ReadBytes(r) }; _rsa = RSA.Create(_parameters);
/// <summary> /// Reads this cache from a serialized data. /// </summary> /// <param name="monitor">The monitor to use.</param> /// <param name="reader">The deserializer to use.</param> /// <returns>True on success, false on error.</returns> public bool Read(IActivityMonitor monitor, ICKBinaryReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } try { _db = new PackageDB(reader); return(true); } catch (Exception ex) { monitor.Error("Unable to read package database.", ex); return(false); } }
public FrontService1 Read(ICKBinaryReader reader, IServiceProvider services) => null !;
/// <summary> /// Simple deserialization constructor. /// </summary> /// <param name="r">The reader.</param> public OneTimePassword(ICKBinaryReader r) { r.ReadByte(); // Version Password = r.ReadString(); Expiration = r.ReadDateTime(); }
internal SymmetricKey(ISystemClock clock, ICKBinaryReader r) : base(clock, r) { r.ReadByte(); _key = r.ReadBytes(r.ReadNonNegativeSmallInt32()); }
public IAmNotAService Read(ICKBinaryReader reader, IServiceProvider services) => null !;
private protected AsymmetricKey(ISystemClock clock, ICKBinaryReader r) : base(clock, r) { r.ReadByte(); // Version }