code: Use std::span where appropriate (#6658)

* code: Use std::span when possible

* code: Prefix memcpy and memcmp with std::
This commit is contained in:
GPUCode
2023-07-07 01:52:40 +03:00
committed by GitHub
parent 4ccd9f24fb
commit cf9bb90ae3
106 changed files with 362 additions and 329 deletions

View File

@@ -31,7 +31,7 @@ std::vector<u8> HexToBytes(const std::string& hex) {
constexpr std::size_t SlotSize = 4;
std::array<RsaSlot, SlotSize> rsa_slots;
std::vector<u8> RsaSlot::GetSignature(const std::vector<u8>& message) const {
std::vector<u8> RsaSlot::GetSignature(std::span<const u8> message) const {
CryptoPP::Integer sig =
CryptoPP::ModularExponentiation(CryptoPP::Integer(message.data(), message.size()),
CryptoPP::Integer(exponent.data(), exponent.size()),
@@ -85,7 +85,7 @@ RsaSlot GetSlot(std::size_t slot_id) {
return rsa_slots[slot_id];
}
std::vector<u8> CreateASN1Message(const std::vector<u8>& data) {
std::vector<u8> CreateASN1Message(std::span<const u8> data) {
static constexpr std::array<u8, 224> asn1_header = {
{0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
@@ -110,4 +110,4 @@ std::vector<u8> CreateASN1Message(const std::vector<u8>& data) {
return message;
}
} // namespace HW::RSA
} // namespace HW::RSA

View File

@@ -4,6 +4,7 @@
#pragma once
#include <span>
#include <vector>
#include "common/common_types.h"
@@ -14,7 +15,7 @@ public:
RsaSlot() = default;
RsaSlot(std::vector<u8> exponent, std::vector<u8> modulus)
: init(true), exponent(std::move(exponent)), modulus(std::move(modulus)) {}
std::vector<u8> GetSignature(const std::vector<u8>& message) const;
std::vector<u8> GetSignature(std::span<const u8> message) const;
explicit operator bool() const {
// TODO(B3N30): Maybe check if exponent and modulus are vailid
@@ -31,6 +32,6 @@ void InitSlots();
RsaSlot GetSlot(std::size_t slot_id);
std::vector<u8> CreateASN1Message(const std::vector<u8>& data);
std::vector<u8> CreateASN1Message(std::span<const u8> data);
} // namespace HW::RSA
} // namespace HW::RSA