Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
 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();
     }
 }
Example #4
0
        /// <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>
 /// Simple deserialization constructor.
 /// </summary>
 /// <param name="r">The reader.</param>
 public OneTimePassword(ICKBinaryReader r)
 {
     r.ReadByte(); // Version
     Password   = r.ReadString();
     Expiration = r.ReadDateTime();
 }