diff --git a/tink/mac/hmac_proto_serialization.cc b/tink/mac/hmac_proto_serialization.cc index aaa6ced4..a52fadf9 100644 --- a/tink/mac/hmac_proto_serialization.cc +++ b/tink/mac/hmac_proto_serialization.cc @@ -156,7 +156,7 @@ util::StatusOr ParseParameters( util::StatusOr hash_type = ToHashType(proto_key_format.params().hash()); - if (!hash_type.ok()) return variant.status(); + if (!hash_type.ok()) return hash_type.status(); return HmacParameters::Create(proto_key_format.key_size(), proto_key_format.params().tag_size(), diff --git a/tink/mac/hmac_proto_serialization_test.cc b/tink/mac/hmac_proto_serialization_test.cc index 82a50f20..5663cf91 100644 --- a/tink/mac/hmac_proto_serialization_test.cc +++ b/tink/mac/hmac_proto_serialization_test.cc @@ -170,6 +170,27 @@ TEST_F(HmacProtoSerializationTest, ParseParametersWithInvalidVersion) { ASSERT_THAT(params.status(), StatusIs(absl::StatusCode::kInvalidArgument)); } +TEST_F(HmacProtoSerializationTest, ParseParametersWithUnknownHashType) { + ASSERT_THAT(RegisterHmacProtoSerialization(), IsOk()); + + HmacKeyFormat key_format_proto; + key_format_proto.set_key_size(16); + key_format_proto.set_version(0); + key_format_proto.mutable_params()->set_tag_size(10); + key_format_proto.mutable_params()->set_hash(HashType::UNKNOWN_HASH); + + util::StatusOr serialization = + internal::ProtoParametersSerialization::Create( + "type.googleapis.com/google.crypto.tink.HmacKey", + OutputPrefixType::RAW, key_format_proto.SerializeAsString()); + ASSERT_THAT(serialization, IsOk()); + + util::StatusOr> params = + internal::MutableSerializationRegistry::GlobalInstance().ParseParameters( + *serialization); + ASSERT_THAT(params.status(), StatusIs(absl::StatusCode::kInvalidArgument)); +} + TEST_F(HmacProtoSerializationTest, ParseParametersWithUnkownOutputPrefix) { ASSERT_THAT(RegisterHmacProtoSerialization(), IsOk());