1/*
2 * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15#include <aws/core/utils/crypto/CryptoStream.h>
16
17namespace Aws
18{
19 namespace Utils
20 {
21 namespace Crypto
22 {
23 static const char* CLASS_TAG = "Aws::Utils::Crypto::SymmetricCryptoStream";
24
25 SymmetricCryptoStream::SymmetricCryptoStream(Aws::IStream& src, CipherMode mode, SymmetricCipher& cipher, size_t bufSize) :
26 Aws::IOStream(m_cryptoBuf = Aws::New<SymmetricCryptoBufSrc>(CLASS_TAG, src, cipher, mode, bufSize)), m_hasOwnership(true)
27 {
28 }
29
30 SymmetricCryptoStream::SymmetricCryptoStream(Aws::OStream& sink, CipherMode mode, SymmetricCipher& cipher, size_t bufSize, int16_t blockOffset) :
31 Aws::IOStream(m_cryptoBuf = Aws::New<SymmetricCryptoBufSink>(CLASS_TAG, sink, cipher, mode, bufSize, blockOffset)), m_hasOwnership(true)
32 {
33 }
34
35 SymmetricCryptoStream::SymmetricCryptoStream(Aws::Utils::Crypto::SymmetricCryptoBufSrc& bufSrc) :
36 Aws::IOStream(&bufSrc), m_cryptoBuf(&bufSrc), m_hasOwnership(false)
37 {
38 }
39
40 SymmetricCryptoStream::SymmetricCryptoStream(Aws::Utils::Crypto::SymmetricCryptoBufSink& bufSink) :
41 Aws::IOStream(&bufSink), m_cryptoBuf(&bufSink), m_hasOwnership(false)
42 {
43 }
44
45 SymmetricCryptoStream::~SymmetricCryptoStream()
46 {
47 Finalize();
48
49 if(m_hasOwnership && m_cryptoBuf)
50 {
51 Aws::Delete(m_cryptoBuf);
52 }
53 }
54
55 void SymmetricCryptoStream::Finalize()
56 {
57 assert(m_cryptoBuf);
58 m_cryptoBuf->Finalize();
59 }
60 }
61 }
62}