/// <summary>
        /// Returns the cached <see cref="ISafeByte" /> for the specified <see cref="byte" />.
        /// </summary>
        /// <param name="byte">The byte.</param>
        public ISafeByte GetByByte(byte @byte)
        {
            EnsureInitialized();
            var id = _byteIdGenerator.Generate(@byte); //Do not skip or cache this step to minimize the amount of time for ids to be seen.

            return(_safeBytesDictionary.Object[id]);
        }
Beispiel #2
0
 /// <exception cref="System.InvalidOperationException">Thrown when byte is already set</exception>
 public void Set(byte b)
 {
     EnsureByteIsNotSet();
     RuntimeHelper.ExecuteCodeWithGuaranteedCleanup(
         () =>
     {
         //Generate ID
         _id = _byteIdGenerator.Generate(b);
         //Encrypt
         Encrypt(b);
         IsByteSet = true;
     },
         () =>
     {
         _memoryProtector.Protect(_encryptionKey);
         _memoryProtector.Protect(_encryptedByte);
     });
 }