Skip to content

Commit 9a55a9c

Browse files
committed
refactoring ChecksumValidatingStreamBuf to separate files
1 parent 55ab564 commit 9a55a9c

File tree

3 files changed

+74
-36
lines changed

3 files changed

+74
-36
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#pragma once
7+
8+
#include <aws/transfer/Transfer_EXPORTS.h>
9+
#include <aws/core/utils/crypto/Hash.h>
10+
#include <memory>
11+
#include <streambuf>
12+
13+
namespace Aws
14+
{
15+
namespace Transfer
16+
{
17+
/**
18+
* Stream buffer wrapper that calculates checksum while forwarding data to underlying stream.
19+
* Used for single-part download checksum validation.
20+
*/
21+
class AWS_TRANSFER_API ChecksumValidatingStreamBuf : public std::streambuf
22+
{
23+
public:
24+
ChecksumValidatingStreamBuf(std::streambuf* underlyingBuf,
25+
std::shared_ptr<Aws::Utils::Crypto::Hash> hash);
26+
27+
std::shared_ptr<Aws::Utils::Crypto::Hash> GetHash() const { return m_hash; }
28+
29+
protected:
30+
std::streamsize xsputn(const char* s, std::streamsize n) override;
31+
int overflow(int c) override;
32+
33+
private:
34+
std::streambuf* m_underlyingBuf;
35+
std::shared_ptr<Aws::Utils::Crypto::Hash> m_hash;
36+
};
37+
}
38+
}

src/aws-cpp-sdk-transfer/include/aws/transfer/TransferHandle.h

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#pragma once
77

88
#include <aws/transfer/Transfer_EXPORTS.h>
9+
#include <aws/transfer/ChecksumValidatingStreamBuf.h>
910
#include <aws/core/utils/memory/stl/AWSString.h>
1011
#include <aws/core/utils/memory/stl/AWSSet.h>
1112
#include <aws/core/utils/memory/stl/AWSMap.h>
@@ -102,42 +103,6 @@ namespace Aws
102103
using PartPointer = std::shared_ptr< PartState >;
103104
using PartStateMap = Aws::Map< int, PartPointer >;
104105

105-
/**
106-
* Stream buffer wrapper that calculates checksum while forwarding data to underlying stream.
107-
* Used for single-part download checksum validation.
108-
*/
109-
class AWS_TRANSFER_API ChecksumValidatingStreamBuf : public std::streambuf
110-
{
111-
public:
112-
ChecksumValidatingStreamBuf(std::streambuf* underlyingBuf,
113-
std::shared_ptr<Aws::Utils::Crypto::Hash> hash)
114-
: m_underlyingBuf(underlyingBuf), m_hash(hash) {}
115-
116-
std::shared_ptr<Aws::Utils::Crypto::Hash> GetHash() const { return m_hash; }
117-
118-
protected:
119-
std::streamsize xsputn(const char* s, std::streamsize n) override
120-
{
121-
if (m_hash && n > 0) {
122-
m_hash->Update(const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(s)), static_cast<size_t>(n));
123-
}
124-
return m_underlyingBuf->sputn(s, n);
125-
}
126-
127-
int overflow(int c) override
128-
{
129-
if (m_hash && c != EOF) {
130-
unsigned char byte = static_cast<unsigned char>(c);
131-
m_hash->Update(&byte, 1);
132-
}
133-
return m_underlyingBuf->sputc(c);
134-
}
135-
136-
private:
137-
std::streambuf* m_underlyingBuf;
138-
std::shared_ptr<Aws::Utils::Crypto::Hash> m_hash;
139-
};
140-
141106
enum class TransferStatus
142107
{
143108
//this value is only used for directory synchronization
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
#include <aws/transfer/ChecksumValidatingStreamBuf.h>
7+
8+
namespace Aws
9+
{
10+
namespace Transfer
11+
{
12+
ChecksumValidatingStreamBuf::ChecksumValidatingStreamBuf(std::streambuf* underlyingBuf,
13+
std::shared_ptr<Aws::Utils::Crypto::Hash> hash)
14+
: m_underlyingBuf(underlyingBuf), m_hash(hash)
15+
{
16+
}
17+
18+
std::streamsize ChecksumValidatingStreamBuf::xsputn(const char* s, std::streamsize n)
19+
{
20+
if (m_hash && n > 0) {
21+
m_hash->Update(const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(s)), static_cast<size_t>(n));
22+
}
23+
return m_underlyingBuf->sputn(s, n);
24+
}
25+
26+
int ChecksumValidatingStreamBuf::overflow(int c)
27+
{
28+
if (c != EOF && m_hash) {
29+
unsigned char byte = static_cast<unsigned char>(c);
30+
m_hash->Update(&byte, 1);
31+
}
32+
return m_underlyingBuf->sputc(c);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)