Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
thaidn authored Mar 20, 2020
2 parents c9776aa + 0fbff9d commit ac7c7fe
Show file tree
Hide file tree
Showing 139 changed files with 804 additions and 636 deletions.
11 changes: 6 additions & 5 deletions cc/aead/aes_ctr_hmac_aead_key_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ Status AesCtrHmacAeadKeyManager::ValidateKey(
}
if (aes_ctr_key.params().iv_size() < kMinIvSizeInBytes ||
aes_ctr_key.params().iv_size() > 16) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKey: IV size out of range.");
return util::Status(util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKey: IV size out of range.");
}
return HmacKeyManager().ValidateKey(key.hmac_key());
}
Expand All @@ -127,14 +127,15 @@ Status AesCtrHmacAeadKeyManager::ValidateKeyFormat(
}
if (aes_ctr_key_format.params().iv_size() < kMinIvSizeInBytes ||
aes_ctr_key_format.params().iv_size() > 16) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKeyFormat: IV size out of range.");
return util::Status(
util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKeyFormat: IV size out of range.");
}

// Validate HmacKeyFormat.
auto hmac_key_format = key_format.hmac_key_format();
if (hmac_key_format.key_size() < kMinKeySizeInBytes) {
return ToStatusF(
return util::Status(
util::error::INVALID_ARGUMENT,
"Invalid AesCtrHmacAeadKeyFormat: HMAC key_size is too small.");
}
Expand Down
4 changes: 2 additions & 2 deletions cc/core/cleartext_keyset_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ util::StatusOr<std::unique_ptr<KeysetHandle>> CleartextKeysetHandle::Read(
crypto::tink::util::Status CleartextKeysetHandle::Write(
KeysetWriter* writer, const KeysetHandle& keyset_handle) {
if (!writer) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"Error KeysetWriter cannot be null");
return util::Status(util::error::INVALID_ARGUMENT,
"Error KeysetWriter cannot be null");
}
return writer->Write(keyset_handle.get_keyset());
}
Expand Down
4 changes: 2 additions & 2 deletions cc/core/crypto_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ crypto::tink::util::StatusOr<std::string> CryptoFormat::get_output_prefix(
case OutputPrefixType::RAW:
return kRawPrefix;
default:
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"The given key has invalid OutputPrefixType.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"The given key has invalid OutputPrefixType.");
}
}

Expand Down
33 changes: 16 additions & 17 deletions cc/core/key_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ TEST(KeyManagerImplTest, FactoryNewKeyFromMessageCallsValidate) {
AesGcmKeyFormat key_format;
key_format.set_key_size(16);
EXPECT_CALL(internal_km, ValidateKeyFormat(_))
.WillOnce(Return(ToStatusF(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromMessageCallsValidate")));
.WillOnce(Return(util::Status(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromMessageCallsValidate")));
EXPECT_THAT(key_manager->get_key_factory().NewKey(key_format).status(),
StatusIs(util::error::OUT_OF_RANGE,
HasSubstr("FactoryNewKeyFromMessageCallsValidate")));
Expand All @@ -179,8 +179,9 @@ TEST(KeyManagerImplTest, FactoryNewKeyFromStringViewCallsValidate) {
AesGcmKeyFormat key_format;
key_format.set_key_size(16);
EXPECT_CALL(internal_km, ValidateKeyFormat(_))
.WillOnce(Return(ToStatusF(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromStringViewCallsValidate")));
.WillOnce(
Return(util::Status(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromStringViewCallsValidate")));
EXPECT_THAT(key_manager->get_key_factory()
.NewKey(key_format.SerializeAsString())
.status(),
Expand All @@ -196,8 +197,8 @@ TEST(KeyManagerImplTest, FactoryNewKeyFromKeyDataCallsValidate) {
AesGcmKeyFormat key_format;
key_format.set_key_size(16);
EXPECT_CALL(internal_km, ValidateKeyFormat(_))
.WillOnce(Return(ToStatusF(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromKeyDataCallsValidate")));
.WillOnce(Return(util::Status(util::error::OUT_OF_RANGE,
"FactoryNewKeyFromKeyDataCallsValidate")));
EXPECT_THAT(key_manager->get_key_factory()
.NewKeyData(key_format.SerializeAsString())
.status(),
Expand Down Expand Up @@ -251,9 +252,9 @@ TEST(CreateDeriverFunctionForTest, UseParametersAndReturnValue) {
TEST(CreateDeriverFunctionForTest, ValidateKeyFormatIsCalled) {
ExampleKeyTypeManager internal_km;
EXPECT_CALL(internal_km, ValidateKeyFormat(_))
.WillOnce(Return(
ToStatusF(util::error::OUT_OF_RANGE,
"CreateDeriverFunctionForTest ValidateKeyFormatIsCalled")));
.WillOnce(Return(util::Status(
util::error::OUT_OF_RANGE,
"CreateDeriverFunctionForTest ValidateKeyFormatIsCalled")));
auto deriver = CreateDeriverFunctionFor(&internal_km);

EXPECT_THAT(
Expand All @@ -269,8 +270,8 @@ TEST(CreateDeriverFunctionForTest, ValidateKeyIsCalled) {
WillOnce(Return(AesGcmKey()));
EXPECT_CALL(internal_km, ValidateKey(_))
.WillOnce(Return(
ToStatusF(util::error::OUT_OF_RANGE,
"CreateDeriverFunctionForTest ValidateKeyIsCalled")));
util::Status(util::error::OUT_OF_RANGE,
"CreateDeriverFunctionForTest ValidateKeyIsCalled")));

auto deriver = CreateDeriverFunctionFor(&internal_km);

Expand Down Expand Up @@ -375,9 +376,8 @@ TEST(KeyManagerImplTest, GetPrimitiveCallsValidate) {
key.ParseFromString(key_data.value());

EXPECT_CALL(internal_km, ValidateKey(_))
.WillOnce(
Return(ToStatusF(util::error::OUT_OF_RANGE,
"GetPrimitiveCallsValidate")));
.WillOnce(Return(util::Status(util::error::OUT_OF_RANGE,
"GetPrimitiveCallsValidate")));
EXPECT_THAT(key_manager->GetPrimitive(key_data).status(),
StatusIs(util::error::OUT_OF_RANGE,
HasSubstr("GetPrimitiveCallsValidate")));
Expand All @@ -398,9 +398,8 @@ TEST(KeyManagerImplTest, GetPrimitiveFromKeyCallsValidate) {
key.ParseFromString(key_data.value());

EXPECT_CALL(internal_km, ValidateKey(_))
.WillOnce(Return(
ToStatusF(util::error::OUT_OF_RANGE,
"GetPrimitiveFromKeyCallsValidate")));
.WillOnce(Return(util::Status(util::error::OUT_OF_RANGE,
"GetPrimitiveFromKeyCallsValidate")));
EXPECT_THAT(key_manager->GetPrimitive(key).status(),
StatusIs(util::error::OUT_OF_RANGE,
HasSubstr("GetPrimitiveFromKeyCallsValidate")));
Expand Down
4 changes: 2 additions & 2 deletions cc/core/private_key_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ TEST(PrivateKeyManagerImplTest, GetPublicKeyDataValidatePrivateKey) {
ExamplePrivateKeyTypeManager private_km;
TestPublicKeyTypeManager public_km;
EXPECT_CALL(private_km, ValidateKey)
.WillOnce(Return(ToStatusF(util::error::OUT_OF_RANGE,
"GetPublicKeyDataValidatePrivateKey")));
.WillOnce(Return(util::Status(util::error::OUT_OF_RANGE,
"GetPublicKeyDataValidatePrivateKey")));

std::unique_ptr<KeyManager<PrivatePrimitive>> key_manager =
MakePrivateKeyManager<PrivatePrimitive>(&private_km, &public_km);
Expand Down
2 changes: 1 addition & 1 deletion cc/core/registry_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ crypto::tink::util::Status RegistryImpl::RegisterPrimitiveWrapper(
typeid(*static_cast<PrimitiveWrapper<P>*>(it->second.get()))) !=
std::type_index(
typeid(*static_cast<PrimitiveWrapper<P>*>(entry.get())))) {
return ToStatusF(
return util::Status(
crypto::tink::util::error::ALREADY_EXISTS,
"A wrapper named for this primitive has already been added.");
}
Expand Down
4 changes: 2 additions & 2 deletions cc/integration/awskms/aws_kms_aead.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ StatusOr<std::string> AwsKmsAead::Decrypt(
auto outcome = aws_client_->Decrypt(req);
if (outcome.IsSuccess()) {
if (outcome.GetResult().GetKeyId() != Aws::String(key_arn_.c_str())) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"AWS KMS decryption failed: wrong key ARN.");
return util::Status(util::error::INVALID_ARGUMENT,
"AWS KMS decryption failed: wrong key ARN.");
}
auto& buffer = outcome.GetResult().GetPlaintext();
std::string plaintext(
Expand Down
8 changes: 4 additions & 4 deletions cc/mac/hmac_key_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ Status HmacKeyManager::ValidateKey(const HmacKey& key) const {
Status status = ValidateVersion(key.version(), get_version());
if (!status.ok()) return status;
if (key.key_value().size() < kMinKeySizeInBytes) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"Invalid HmacKey: key_value is too short.");
return util::Status(util::error::INVALID_ARGUMENT,
"Invalid HmacKey: key_value is too short.");
}
return ValidateParams(key.params());
}
Expand All @@ -122,8 +122,8 @@ Status HmacKeyManager::ValidateKey(const HmacKey& key) const {
Status HmacKeyManager::ValidateKeyFormat(
const HmacKeyFormat& key_format) const {
if (key_format.key_size() < kMinKeySizeInBytes) {
return ToStatusF(util::error::INVALID_ARGUMENT,
"Invalid HmacKeyFormat: key_size is too small.");
return util::Status(util::error::INVALID_ARGUMENT,
"Invalid HmacKeyFormat: key_size is too small.");
}
return ValidateParams(key_format.params());
}
Expand Down
22 changes: 11 additions & 11 deletions cc/primitive_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ class PrimitiveSet {
static crypto::tink::util::StatusOr<std::unique_ptr<Entry<P>>> New(
std::unique_ptr<P> primitive, google::crypto::tink::Keyset::Key key) {
if (key.status() != google::crypto::tink::KeyStatusType::ENABLED) {
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"The key must be ENABLED.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"The key must be ENABLED.");
}
auto identifier_result = CryptoFormat::get_output_prefix(key);
if (!identifier_result.ok()) return identifier_result.status();
if (primitive == nullptr) {
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"The primitive must be non-null.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"The primitive must be non-null.");
}
std::string identifier = identifier_result.ValueOrDie();
return absl::WrapUnique(new Entry(std::move(primitive), identifier,
Expand Down Expand Up @@ -142,18 +142,18 @@ class PrimitiveSet {
// Sets the given 'primary' as the primary primitive of this set.
crypto::tink::util::Status set_primary(Entry<P>* primary) {
if (!primary) {
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"The primary primitive must be non-null.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"The primary primitive must be non-null.");
}
if (primary->get_status() != google::crypto::tink::KeyStatusType::ENABLED) {
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"Primary has to be enabled.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"Primary has to be enabled.");
}
auto entries_result = get_primitives(primary->get_identifier());
if (!entries_result.ok()) {
return ToStatusF(crypto::tink::util::error::INVALID_ARGUMENT,
"Primary cannot be set to an entry which is "
"not held by this primitive set.");
return util::Status(crypto::tink::util::error::INVALID_ARGUMENT,
"Primary cannot be set to an entry which is "
"not held by this primitive set.");
}

primary_ = primary;
Expand Down
Loading

0 comments on commit ac7c7fe

Please sign in to comment.