public void ComputeEncodedLength_WalrusContentDefaultKeyRecordSize4096_ReturnsCorrectLength()
        {
            byte[] contentToEncode = Encoding.UTF8.GetBytes(WALRUS_CONTENT);

            long encodedContentLength;

            using (MemoryStream source = new MemoryStream(contentToEncode))
            {
                encodedContentLength = Aes128GcmEncoding.ComputeEncodedLength(source.Length, 0, RECORD_SIZE_4096);
            }

            Assert.Equal(WALRUS_CONTENT_ENCODED_LENGTH, encodedContentLength);
        }
        public async Task DecodeAsync_WalrusEncodedAsMultipleRecordsWithoutPadding_DecodesWalrusContent()
        {
            byte[] contentToDecode = Convert.FromBase64String(WALRUS_CONTENT_ENCODED_AS_MULTIPLE_RECORDS_WITHOUT_PADDING_BASE64);

            string decodedContent = null;

            using (MemoryStream source = new MemoryStream(contentToDecode))
            {
                using (MemoryStream destination = new MemoryStream())
                {
                    await Aes128GcmEncoding.DecodeAsync(source, destination, (keyId) => KEYS[keyId ?? DEFAULT_KEY_ID]);

                    decodedContent = Encoding.UTF8.GetString(destination.ToArray());
                }
            }

            Assert.Equal(WALRUS_CONTENT, decodedContent);
        }
        public async Task EncodeAsync_WalrusContentNonRandomSaltDefaultKeyRecordSize4096_EncodesAsSingleRecord()
        {
            byte[] contentToEncode = Encoding.UTF8.GetBytes(WALRUS_CONTENT);
            byte[] salt            = Convert.FromBase64String(NON_RANDOM_SALT);

            string encodedContent = null;

            using (MemoryStream source = new MemoryStream(contentToEncode))
            {
                using (MemoryStream destination = new MemoryStream())
                {
                    await Aes128GcmEncoding.EncodeAsync(source, destination, salt, KEYS[DEFAULT_KEY_ID], (byte[])null, RECORD_SIZE_4096);

                    encodedContent = Convert.ToBase64String(destination.ToArray());
                }
            }

            Assert.Equal(WALRUS_CONTENT_ENCODED_AS_SINGLE_RECORD_BASE64, encodedContent);
        }
 public Task DecodeMultipleRecordsAsync()
 {
     _decodeMultipleRecordsSource.Seek(0, SeekOrigin.Begin);
     return(Aes128GcmEncoding.DecodeAsync(_decodeMultipleRecordsSource, Stream.Null, (string keyId) => KEY));
 }
 public Task EncodeMultipleRecordsAsync()
 {
     _encodeMultipleRecordsSource.Seek(0, SeekOrigin.Begin);
     return(Aes128GcmEncoding.EncodeAsync(_encodeMultipleRecordsSource, Stream.Null, KEY, KEY_ID, RECORD_SIZE_4096));
 }