proxygen
OpenSSLHashTest.cpp File Reference

Go to the source code of this file.

Functions

 TEST_F (OpenSSLHashTest, sha256)
 
 TEST_F (OpenSSLHashTest, sha256_hashcopy)
 
 TEST_F (OpenSSLHashTest, sha256_hashcopy_intermediate)
 
 TEST_F (OpenSSLHashTest, hmac_sha256)
 

Function Documentation

TEST_F ( OpenSSLHashTest  ,
sha256   
)

Definition at line 31 of file OpenSSLHashTest.cpp.

References folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, folly::IOBuf::prependChain(), folly::gen::range(), and folly::ssl::SHA256.

31  {
32  IOBuf buf;
33  buf.prependChain(IOBuf::wrapBuffer(ByteRange(StringPiece("foo"))));
34  buf.prependChain(IOBuf::wrapBuffer(ByteRange(StringPiece("bar"))));
35  EXPECT_EQ(3, buf.countChainElements());
37 
38  auto expected = vector<uint8_t>(32);
39  auto combined = ByteRange(StringPiece("foobar"));
40  SHA256(combined.data(), combined.size(), expected.data());
41 
42  auto out = vector<uint8_t>(32);
43  OpenSSLHash::sha256(range(out), buf);
44  EXPECT_EQ(expected, out);
45 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t countChainElements() const
Definition: IOBuf.cpp:493
Gen range(Value begin, Value end)
Definition: Base.h:467
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
Definition: IOBuf.cpp:509
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
Range< const char * > StringPiece
TEST_F ( OpenSSLHashTest  ,
sha256_hashcopy   
)

Definition at line 47 of file OpenSSLHashTest.cpp.

References folly::copy(), EXPECT_EQ, folly::ssl::OpenSSLHash::Digest::hash_final(), folly::ssl::OpenSSLHash::Digest::hash_init(), folly::ssl::OpenSSLHash::Digest::hash_update(), and folly::gen::range().

47  {
48  std::array<uint8_t, 32> expected, actual;
49 
50  OpenSSLHash::Digest digest;
51  digest.hash_init(EVP_sha256());
52  digest.hash_update(ByteRange(StringPiece("foobar")));
53 
54  OpenSSLHash::Digest copy(digest);
55 
56  digest.hash_final(range(expected));
57  copy.hash_final(range(actual));
58 
59  EXPECT_EQ(expected, actual);
60 }
void hash_init(const EVP_MD *md)
Definition: OpenSSLHash.h:49
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen range(Value begin, Value end)
Definition: Base.h:467
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
void hash_final(MutableByteRange out)
Definition: OpenSSLHash.h:62
void hash_update(ByteRange data)
Definition: OpenSSLHash.h:53
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
Range< const char * > StringPiece
TEST_F ( OpenSSLHashTest  ,
sha256_hashcopy_intermediate   
)

Definition at line 62 of file OpenSSLHashTest.cpp.

References folly::copy(), EXPECT_EQ, folly::ssl::OpenSSLHash::Digest::hash_final(), folly::ssl::OpenSSLHash::Digest::hash_init(), folly::ssl::OpenSSLHash::Digest::hash_update(), and folly::gen::range().

62  {
63  std::array<uint8_t, 32> expected, actual;
64 
65  OpenSSLHash::Digest digest;
66  digest.hash_init(EVP_sha256());
67  digest.hash_update(ByteRange(StringPiece("foo")));
68 
69  OpenSSLHash::Digest copy(digest);
70 
71  digest.hash_update(ByteRange(StringPiece("bar")));
72  copy.hash_update(ByteRange(StringPiece("bar")));
73 
74  digest.hash_final(range(expected));
75  copy.hash_final(range(actual));
76 
77  EXPECT_EQ(expected, actual);
78 }
void hash_init(const EVP_MD *md)
Definition: OpenSSLHash.h:49
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
Gen range(Value begin, Value end)
Definition: Base.h:467
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
void hash_final(MutableByteRange out)
Definition: OpenSSLHash.h:62
void hash_update(ByteRange data)
Definition: OpenSSLHash.h:53
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
Range< const char * > StringPiece
TEST_F ( OpenSSLHashTest  ,
hmac_sha256   
)

Definition at line 80 of file OpenSSLHashTest.cpp.

References folly::IOBuf::computeChainDataLength(), folly::IOBuf::countChainElements(), EXPECT_EQ, folly::IOBuf::prependChain(), and folly::gen::range().

80  {
81  auto key = ByteRange(StringPiece("qwerty"));
82 
83  IOBuf buf;
84  buf.prependChain(IOBuf::wrapBuffer(ByteRange(StringPiece("foo"))));
85  buf.prependChain(IOBuf::wrapBuffer(ByteRange(StringPiece("bar"))));
86  EXPECT_EQ(3, buf.countChainElements());
88 
89  auto expected = vector<uint8_t>(32);
90  auto combined = ByteRange(StringPiece("foobar"));
91  HMAC(
92  EVP_sha256(),
93  key.data(),
94  int(key.size()),
95  combined.data(),
96  combined.size(),
97  expected.data(),
98  nullptr);
99 
100  auto out = vector<uint8_t>(32);
101  OpenSSLHash::hmac_sha256(range(out), key, buf);
102  EXPECT_EQ(expected, out);
103 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
size_t countChainElements() const
Definition: IOBuf.cpp:493
Gen range(Value begin, Value end)
Definition: Base.h:467
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
Definition: IOBuf.cpp:509
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
Range< const unsigned char * > ByteRange
Definition: Range.h:1163
Range< const char * > StringPiece