Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more precision to error messages #108

Merged
merged 1 commit into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_list_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl TryFrom<KeyInfoProto> for KeyInfo {
let attributes = proto_info
.attributes
.ok_or_else(|| {
error!("attributes field of KeyInfo protobuf message is empty.");
error!("The attributes field of KeyInfo protobuf message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?;
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_aead_decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl TryFrom<OperationProto> for Operation {
alg: proto_op
.alg
.ok_or_else(|| {
error!("alg field of PsaAeadDecrypt::Operation message is empty.");
error!("The alg field of PsaAeadDecrypt::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_aead_encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl TryFrom<OperationProto> for Operation {
alg: proto_op
.alg
.ok_or_else(|| {
error!("alg field of PsaAeadEncrypt::Operation message is empty.");
error!("The alg field of PsaAeadEncrypt::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
38 changes: 19 additions & 19 deletions src/operations_protobuf/convert_psa_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TryFrom<HashProto> for Hash {
fn try_from(hash_val: HashProto) -> Result<Self> {
match hash_val {
HashProto::None => {
error!("The None value of Hash enumeration is not allowed.");
error!("The None value of Hash enumeration is not allowed (mandatory field).");
Err(ResponseStatus::InvalidEncoding)
}
#[allow(deprecated)]
Expand Down Expand Up @@ -102,7 +102,7 @@ impl TryFrom<SignHashProto> for SignHash {

fn try_from(sign_hash_val: SignHashProto) -> Result<Self> {
match sign_hash_val.variant.ok_or_else(|| {
error!("variant field of SignHash message is empty.");
error!("The SignHash variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
sign_hash::Variant::Any(_) => Ok(SignHash::Any),
Expand Down Expand Up @@ -132,7 +132,7 @@ impl TryFrom<FullLengthMacProto> for FullLengthMac {

fn try_from(alg: FullLengthMacProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of mac::FullLength message is empty.");
error!("The FullLengthMac variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
mac::full_length::Variant::Hmac(hmac) => Ok(FullLengthMac::Hmac {
Expand Down Expand Up @@ -173,13 +173,13 @@ impl TryFrom<MacProto> for Mac {

fn try_from(alg: MacProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of Mac message is empty.");
error!("The Mac variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
mac::Variant::FullLength(full_length) => Ok(Mac::FullLength(full_length.try_into()?)),
mac::Variant::Truncated(truncated) => Ok(Mac::Truncated {
mac_alg: truncated.mac_alg.ok_or_else(|| {
error!("mac_alg field of mac::Truncated message is empty.");
error!("The mac_alg field of mac::Truncated message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?.try_into()?,
mac_length: truncated.mac_length.try_into().map_err(|e| {
Expand Down Expand Up @@ -226,7 +226,7 @@ impl TryFrom<CipherProto> for Cipher {
fn try_from(cipher_val: CipherProto) -> Result<Self> {
match cipher_val {
CipherProto::None => {
error!("The None value of Cipher enumeration is not allowed.");
error!("The None value of Cipher enumeration is not allowed (mandatory field).");
Err(ResponseStatus::InvalidEncoding)
}
CipherProto::StreamCipher => Ok(Cipher::StreamCipher),
Expand Down Expand Up @@ -262,7 +262,7 @@ impl TryFrom<AeadWithDefaultLengthTagProto> for AeadWithDefaultLengthTag {
fn try_from(aead_val: AeadWithDefaultLengthTagProto) -> Result<Self> {
match aead_val {
AeadWithDefaultLengthTagProto::None => {
error!("The None value of AeadWithDefaultLengthTag enumeration is not allowed.");
error!("The None value of AeadWithDefaultLengthTag enumeration is not allowed (mandatory field).");
Err(ResponseStatus::InvalidEncoding)
}
AeadWithDefaultLengthTagProto::Ccm => Ok(AeadWithDefaultLengthTag::Ccm),
Expand Down Expand Up @@ -291,7 +291,7 @@ impl TryFrom<AeadProto> for Aead {

fn try_from(alg: AeadProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of Aead message is empty.");
error!("The Aead variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
aead::Variant::AeadWithDefaultLengthTag(aead_with_default_length_tag) => {
Expand Down Expand Up @@ -336,15 +336,15 @@ impl TryFrom<AsymmetricSignatureProto> for AsymmetricSignature {

fn try_from(alg: AsymmetricSignatureProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of Asym message is empty.");
error!("The AsymmetricSignature variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
asymmetric_signature::Variant::RsaPkcs1v15Sign(rsa_pkcs1v15_sign) => {
Ok(AsymmetricSignature::RsaPkcs1v15Sign {
hash_alg: rsa_pkcs1v15_sign
.hash_alg
.ok_or_else(|| {
error!("hash_alg field of RsaPkcs1v15Sign message is empty.");
error!("The hash_alg field of RsaPkcs1v15Sign message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand All @@ -357,7 +357,7 @@ impl TryFrom<AsymmetricSignatureProto> for AsymmetricSignature {
hash_alg: rsa_pss
.hash_alg
.ok_or_else(|| {
error!("hash_alg field of RsaPss message is empty.");
error!("The hash_alg field of RsaPss message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand All @@ -366,7 +366,7 @@ impl TryFrom<AsymmetricSignatureProto> for AsymmetricSignature {
hash_alg: ecdsa
.hash_alg
.ok_or_else(|| {
error!("hash_alg field of Ecdsa message is empty.");
error!("The hash_alg field of Ecdsa message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand All @@ -377,7 +377,7 @@ impl TryFrom<AsymmetricSignatureProto> for AsymmetricSignature {
hash_alg: deterministic_ecdsa
.hash_alg
.ok_or_else(|| {
error!("hash_alg field of DeterministicEcdsa message is empty.");
error!("The hash_alg field of DeterministicEcdsa message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down Expand Up @@ -441,7 +441,7 @@ impl TryFrom<AsymmetricEncryptionProto> for AsymmetricEncryption {

fn try_from(alg: AsymmetricEncryptionProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of AsymmetricSignature message is empty.");
error!("The AsymmetricSignature variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
asymmetric_encryption::Variant::RsaPkcs1v15Crypt(_) => {
Expand Down Expand Up @@ -485,7 +485,7 @@ impl TryFrom<RawKeyAgreementProto> for RawKeyAgreement {
fn try_from(raw_key_agreement_val: RawKeyAgreementProto) -> Result<Self> {
match raw_key_agreement_val {
RawKeyAgreementProto::None => {
error!("The None value of RawKeyAgreement enumeration is not allowed.");
error!("The None value of RawKeyAgreement enumeration is not allowed (mandatory field).");
Err(ResponseStatus::InvalidEncoding)
}
RawKeyAgreementProto::Ffdh => Ok(RawKeyAgreement::Ffdh),
Expand Down Expand Up @@ -514,14 +514,14 @@ impl TryFrom<KeyAgreementProto> for KeyAgreement {

fn try_from(alg: KeyAgreementProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of KeyAgreement message is empty.");
error!("The KeyAgreement variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
key_agreement::Variant::Raw(raw) => Ok(KeyAgreement::Raw(RawKeyAgreementProto::try_from(raw)?.try_into()?)),
key_agreement::Variant::WithKeyDerivation(with_key_derivation) => Ok(KeyAgreement::WithKeyDerivation {
ka_alg: RawKeyAgreementProto::try_from(with_key_derivation.ka_alg)?.try_into()?,
kdf_alg: with_key_derivation.kdf_alg.ok_or_else(|| {
error!("kdf_alg field of key_agreement::WithKeyDerivation message is empty.");
error!("The kdf_alg field of key_agreement::WithKeyDerivation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?.try_into()?,
}),
Expand Down Expand Up @@ -558,7 +558,7 @@ impl TryFrom<KeyDerivationProto> for KeyDerivation {

fn try_from(alg: KeyDerivationProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of KeyDerivation message is empty.");
error!("The KeyDerivation variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
key_derivation::Variant::Hkdf(hkdf) => Ok(KeyDerivation::Hkdf {
Expand Down Expand Up @@ -611,7 +611,7 @@ impl TryFrom<AlgorithmProto> for Algorithm {

fn try_from(alg: AlgorithmProto) -> Result<Self> {
match alg.variant.ok_or_else(|| {
error!("variant field of Algorithm message is empty.");
error!("The Algorithm variant used is not supported.");
ResponseStatus::InvalidEncoding
})? {
algorithm::Variant::None(_) => Ok(Algorithm::None),
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_asymmetric_decrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl TryFrom<OperationProto> for Operation {
alg: proto_op
.alg
.ok_or_else(|| {
error!("alg field of PsaAsymmetricDecrypt::Operation message is empty.");
error!("The alg field of PsaAsymmetricDecrypt::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_asymmetric_encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl TryFrom<OperationProto> for Operation {
alg: proto_op
.alg
.ok_or_else(|| {
error!("alg field of PsaAsymmetricEncrypt::Operation message is empty.");
error!("The alg field of PsaAsymmetricEncrypt::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_generate_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl TryFrom<OperationProto> for Operation {
attributes: proto_op
.attributes
.ok_or_else(|| {
error!("attributes field of PsaGenerateKey::Operation message is empty.");
error!("The attributes field of PsaGenerateKey::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
2 changes: 1 addition & 1 deletion src/operations_protobuf/convert_psa_import_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl TryFrom<OperationProto> for Operation {
attributes: proto_op
.attributes
.ok_or_else(|| {
error!("attributes field of PsaImportKey::Operation message is empty.");
error!("The attributes field of PsaImportKey::Operation message is not set (mandatory field).");
ResponseStatus::InvalidEncoding
})?
.try_into()?,
Expand Down
Loading