Botan 3.13.0
Crypto and TLS for C&
Botan::PK_Ops::Verification_with_Hash Class Referenceabstract

#include <pk_ops_impl.h>

Inheritance diagram for Botan::PK_Ops::Verification_with_Hash:
Botan::PK_Ops::Verification

Public Member Functions

std::string hash_function () const final
bool is_valid_signature (std::span< const uint8_t > sig) override
void update (std::span< const uint8_t > input) override
 ~Verification_with_Hash () override

Protected Member Functions

 Verification_with_Hash (const AlgorithmIdentifier &alg_id, std::string_view pk_algo, bool allow_null_parameters=false)
 Verification_with_Hash (std::string_view hash)
virtual bool verify (std::span< const uint8_t > msg, std::span< const uint8_t > sig)=0

Detailed Description

Definition at line 57 of file pk_ops_impl.h.

Constructor & Destructor Documentation

◆ ~Verification_with_Hash()

Botan::PK_Ops::Verification_with_Hash::~Verification_with_Hash ( )
overridedefault

◆ Verification_with_Hash() [1/2]

Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash ( std::string_view hash)
explicitprotected

Definition at line 161 of file pk_ops.cpp.

161 :
162 Verification(), m_hash(create_signature_hash(padding)) {}

Referenced by ~Verification_with_Hash().

◆ Verification_with_Hash() [2/2]

Botan::PK_Ops::Verification_with_Hash::Verification_with_Hash ( const AlgorithmIdentifier & alg_id,
std::string_view pk_algo,
bool allow_null_parameters = false )
explicitprotected

Definition at line 170 of file pk_ops.cpp.

172 {
173 const auto oid_name = alg_id.oid().registered_name();
174 if(!oid_name) {
175 throw Decoding_Error(
176 fmt("Unexpected AlgorithmIdentifier OID {} in association with {} key", alg_id.oid(), pk_algo));
177 }
178
179 const auto oid_info = split_on(*oid_name, '/');
180
181 if(oid_info.size() != 2 || oid_info[0] != pk_algo) {
182 throw Decoding_Error(
183 fmt("Unexpected AlgorithmIdentifier OID {} in association with {} key", alg_id.oid(), pk_algo));
184 }
185
186 if(!alg_id.parameters_are_empty()) {
187 if(alg_id.parameters_are_null()) {
188 if(!allow_null_parameters) {
189 throw Decoding_Error(fmt("Unexpected NULL AlgorithmIdentifier parameters for {}", pk_algo));
190 }
191 } else {
192 throw Decoding_Error(fmt("Unexpected AlgorithmIdentifier parameters for {}", pk_algo));
193 }
194 }
195
196 m_hash = HashFunction::create_or_throw(oid_info[1]);
197}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
std::vector< std::string > split_on(std::string_view str, char delim)
Definition parsing.cpp:141

References Botan::HashFunction::create_or_throw(), Botan::fmt(), Botan::AlgorithmIdentifier::oid(), Botan::AlgorithmIdentifier::parameters_are_empty(), Botan::AlgorithmIdentifier::parameters_are_null(), Botan::OID::registered_name(), and Botan::split_on().

Member Function Documentation

◆ hash_function()

std::string Botan::PK_Ops::Verification_with_Hash::hash_function ( ) const
finalvirtual

Return the hash function being used by this signer

Implements Botan::PK_Ops::Verification.

Definition at line 166 of file pk_ops.cpp.

166 {
167 return m_hash->name();
168}

◆ is_valid_signature()

bool Botan::PK_Ops::Verification_with_Hash::is_valid_signature ( std::span< const uint8_t > sig)
overridevirtual

Perform a verification operation

Parameters
sigthe signature to be checked with respect to the input

Implements Botan::PK_Ops::Verification.

Definition at line 203 of file pk_ops.cpp.

203 {
204 const std::vector<uint8_t> msg = m_hash->final_stdvec();
205 return verify(msg, sig);
206}
virtual bool verify(std::span< const uint8_t > msg, std::span< const uint8_t > sig)=0

References verify().

◆ update()

void Botan::PK_Ops::Verification_with_Hash::update ( std::span< const uint8_t > input)
overridevirtual

Add more data to the message currently being signed

Parameters
inputthe input to be hashed/verified

Implements Botan::PK_Ops::Verification.

Definition at line 199 of file pk_ops.cpp.

199 {
200 m_hash->update(msg);
201}

◆ verify()

virtual bool Botan::PK_Ops::Verification_with_Hash::verify ( std::span< const uint8_t > msg,
std::span< const uint8_t > sig )
protectedpure virtual

Perform a signature check operation

Parameters
msgthe message
sigthe signature
Returns
if sig is a valid signature for msg

References verify().

Referenced by is_valid_signature(), and verify().


The documentation for this class was generated from the following files: