diff options
author | Maksim Ivanov <emaxx@google.com> | 2018-05-29 21:02:42 +0200 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-31 12:26:11 -0700 |
commit | 6bc9c1d7fe169e5e8ceb294e0b8a6cd5cadbbec5 (patch) | |
tree | 193334b93651097ae73c93b93e92c06f7c3835ed | |
parent | c4075810a258bbc60c7bcf0617c1dcb995edc8a8 (diff) | |
download | platform_external_libbrillo-6bc9c1d7fe169e5e8ceb294e0b8a6cd5cadbbec5.tar.gz platform_external_libbrillo-6bc9c1d7fe169e5e8ceb294e0b8a6cd5cadbbec5.tar.bz2 platform_external_libbrillo-6bc9c1d7fe169e5e8ceb294e0b8a6cd5cadbbec5.zip |
libbrillo: Add SecureBlob constructor from Blob
Add an explicit constructor that allows to convert Blob
into SecureBlob.
This should be useful during the transition period while
moving away from SecureBlob - if some code has mixed use
of Blob's and SecureBlob's, then the new constructor will
allow to avoid typing long iterator-based conversions.
BUG=chromium:728047
TEST=new unit test (SecureBlobTest.BlobConstructorTest)
Change-Id: Icad5f0817174f9ec671580dce402a7c361113b6a
Reviewed-on: https://chromium-review.googlesource.com/1076631
Commit-Ready: Maksim Ivanov <emaxx@chromium.org>
Tested-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Dan Erat <derat@chromium.org>
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
-rw-r--r-- | brillo/secure_blob.cc | 3 | ||||
-rw-r--r-- | brillo/secure_blob.h | 1 | ||||
-rw-r--r-- | brillo/secure_blob_unittest.cc | 9 |
3 files changed, 13 insertions, 0 deletions
diff --git a/brillo/secure_blob.cc b/brillo/secure_blob.cc index 58cd594..8b4a8b1 100644 --- a/brillo/secure_blob.cc +++ b/brillo/secure_blob.cc @@ -10,6 +10,9 @@ namespace brillo { +SecureBlob::SecureBlob(const Blob& blob) + : SecureBlob(blob.begin(), blob.end()) {} + SecureBlob::SecureBlob(const std::string& data) : SecureBlob(data.begin(), data.end()) {} diff --git a/brillo/secure_blob.h b/brillo/secure_blob.h index 86f43eb..914093a 100644 --- a/brillo/secure_blob.h +++ b/brillo/secure_blob.h @@ -21,6 +21,7 @@ class BRILLO_EXPORT SecureBlob : public Blob { public: SecureBlob() = default; using Blob::vector; // Inherit standard constructors from vector. + explicit SecureBlob(const Blob& blob); explicit SecureBlob(const std::string& data); ~SecureBlob(); diff --git a/brillo/secure_blob_unittest.cc b/brillo/secure_blob_unittest.cc index aa2684e..e4ed486 100644 --- a/brillo/secure_blob_unittest.cc +++ b/brillo/secure_blob_unittest.cc @@ -43,6 +43,15 @@ class SecureBlobTest : public ::testing::Test { DISALLOW_COPY_AND_ASSIGN(SecureBlobTest); }; +// Test construction of SecureBlob from Blob. +TEST_F(SecureBlobTest, BlobConstructorTest) { + const std::vector<uint8_t> bytes = {0, 1, 255}; + const Blob blob(bytes); + const SecureBlob secure_blob(blob); + EXPECT_EQ(bytes, + std::vector<uint8_t>(secure_blob.begin(), secure_blob.end())); +} + TEST_F(SecureBlobTest, AllocationSizeTest) { // Check that allocating a SecureBlob of a specified size works SecureBlob blob(32); |