37 #include <openssl/crypto.h>
47 ParseResult() =
default;
59 span<const uint8_t>
sig;
69 using namespace transform;
95 parse(
const Data& data)
101 catch (
const tlv::Error&) {
110 interest.wireEncode();
112 if (interest.getSignatureInfo() && interest.getSignatureValue().isValid()) {
114 return {*interest.getSignatureInfo(), interest.extractSignedRanges(),
115 interest.getSignatureValue().value_bytes()};
119 const Name& interestName = interest.getName();
124 const Block& nameBlock = interestName.wireEncode();
130 sigValue.value_bytes()};
133 catch (
const tlv::Error&) {
139 verifySignature(
const ParseResult& params,
const transform::PublicKey& key)
141 return !params.bufs.empty() &&
verifySignature(params.bufs, params.sig, key);
147 return !params.bufs.empty() &&
verifySignature(params.bufs, params.sig, key);
154 return !params.bufs.empty() && bool(tpm.verify(params.bufs, params.sig, keyName, digestAlgorithm));
160 if (params.bufs.empty()) {
166 using namespace transform;
169 catch (
const transform::Error&) {
172 auto result = os.buf();
174 if (result->size() != params.sig.size()) {
179 return CRYPTO_memcmp(result->data(), params.sig.data(), params.sig.size()) == 0;
221 auto parsed = parse(data);
237 auto parsed = parse(interest);
261 return verifySignature(parse(interest), tpm, keyName, digestAlgorithm);
span< const uint8_t > value_bytes() const noexcept
Return a read-only view of TLV-VALUE as a contiguous range of bytes.
Represents a Data packet.
InputBuffers extractSignedRanges() const
Extract ranges of Data covered by the signature.
const SignatureInfo & getSignatureInfo() const noexcept
Get the SignatureInfo element.
const Block & getSignatureValue() const noexcept
Get the SignatureValue element.
Represents an Interest packet.
Represents an absolute name.
Frontend handle for a key in the PIB.
span< const uint8_t > getPublicKey() const
Return the raw public key bits.
bool verifySignature(const InputBuffers &blobs, span< const uint8_t > sig, const transform::PublicKey &key)
Verify blobs using key against sig.
const ssize_t POS_SIG_VALUE
const size_t MIN_SIZE
Minimum number of name components for an old-style Signed Interest.
const ssize_t POS_SIG_INFO
span< const uint8_t > sig