Skip to content

Commit 4a05dba

Browse files
Feature/make secp256l1 parameters const (#39)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 3a2c2c9 commit 4a05dba

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

include/libp2p/crypto/secp256k1_provider.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace libp2p::crypto::secp256k1 {
3838
* @return Secp256k1 signature or error code
3939
*/
4040
virtual outcome::result<Signature> sign(
41-
gsl::span<uint8_t> message, const PrivateKey &key) const = 0;
41+
gsl::span<const uint8_t> message, const PrivateKey &key) const = 0;
4242

4343
/**
4444
* @brief Verify signature for a message
@@ -47,7 +47,7 @@ namespace libp2p::crypto::secp256k1 {
4747
* @param key - public key for signature verifying
4848
* @return Result of the verification or error code
4949
*/
50-
virtual outcome::result<bool> verify(gsl::span<uint8_t> message,
50+
virtual outcome::result<bool> verify(gsl::span<const uint8_t> message,
5151
const Signature &signature,
5252
const PublicKey &key) const = 0;
5353

include/libp2p/crypto/secp256k1_provider/secp256k1_provider_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace libp2p::crypto::secp256k1 {
2020
const PrivateKey &key) const override;
2121

2222
outcome::result<Signature> sign(
23-
gsl::span<uint8_t> message,
23+
gsl::span<const uint8_t> message,
2424
const PrivateKey &key) const override;
2525

26-
outcome::result<bool> verify(gsl::span<uint8_t> message,
26+
outcome::result<bool> verify(gsl::span<const uint8_t> message,
2727
const Signature &signature,
2828
const PublicKey &key) const override;
2929

include/libp2p/crypto/secp256k1_types.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
#include <array>
1111

1212
namespace libp2p::crypto::secp256k1 {
13+
14+
static const size_t kPrivateKeyLength = 32;
15+
static const size_t kPublicKeyLength = 33;
1316
/**
1417
* @brief Common types
1518
*/
16-
using PrivateKey = std::array<uint8_t, 32>;
17-
using PublicKey = std::array<uint8_t, 33>;
19+
using PrivateKey = std::array<uint8_t, kPrivateKeyLength>;
20+
using PublicKey = std::array<uint8_t, kPublicKeyLength>;
1821
using Signature = std::vector<uint8_t>;
1922

2023
/**

src/crypto/secp256k1_provider/secp256k1_provider_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ namespace libp2p::crypto::secp256k1 {
5353
}
5454

5555
outcome::result<Signature> Secp256k1ProviderImpl::sign(
56-
gsl::span<uint8_t> message, const PrivateKey &key) const {
56+
gsl::span<const uint8_t> message, const PrivateKey &key) const {
5757
common::Hash256 digest = sha256(message);
5858
OUTCOME_TRY(private_key, bytesToPrivateKey(key));
5959
OUTCOME_TRY(signature, GenerateEcSignature(digest, private_key));
6060
return std::move(signature);
6161
}
6262

6363
outcome::result<bool> Secp256k1ProviderImpl::verify(
64-
gsl::span<uint8_t> message, const Signature &signature,
64+
gsl::span<const uint8_t> message, const Signature &signature,
6565
const PublicKey &key) const {
6666
common::Hash256 digest = sha256(message);
6767
OUTCOME_TRY(public_key, bytesToPublicKey(key));

0 commit comments

Comments
 (0)