Skip to content

Commit

Permalink
docs: Removed unprofessional statement in visit_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed May 8, 2024
1 parent 4b5481a commit c16e406
Show file tree
Hide file tree
Showing 46 changed files with 101 additions and 240 deletions.
2 changes: 1 addition & 1 deletion src/base/visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace sgns
}

/**
* @brief Inplace visitor for boost::variant. Bascially poor man's pattern matching for variants.
* @brief Inplace visitor for boost::variant.
* @code{.cpp}
* boost::variant<int, std::string> value = "1234";
*
Expand Down
10 changes: 2 additions & 8 deletions src/crypto/crypto_store.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@


#ifndef SUPERGENIUS_CRYPTO_STORE_HPP
#define SUPERGENIUS_CRYPTO_STORE_HPP

#include <memory>

#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
#include <libp2p/crypto/key.hpp>
#include "crypto/bip39/bip39_provider.hpp"
#include "crypto/crypto_store/key_type.hpp"
#include "crypto/ed25519_types.hpp"
#include "crypto/secp256k1_types.hpp"
#include "crypto/sr25519_types.hpp"

namespace sgns::crypto {
Expand Down Expand Up @@ -110,6 +104,6 @@ namespace sgns::crypto {
*/
virtual SR25519Keys getSr25519PublicKeys(KeyTypeId key_type) const = 0;
};
} // namespace sgns::crypto
}

#endif // SUPERGENIUS_CRYPTO_STORE_HPP
#endif
18 changes: 10 additions & 8 deletions src/crypto/crypto_store/crypto_store_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@


#include "crypto/crypto_store/crypto_store_impl.hpp"

#include <fstream>

#include <gsl/span>
#include "base/visitor.hpp"
#include "crypto/bip39/mnemonic.hpp"
#include <set>

Expand All @@ -32,9 +29,14 @@ namespace sgns::crypto {
}

std::ifstream file;
auto close_file = gsl::finally([&file] {
if (file.is_open()) file.close();
});
auto close_file = gsl::finally(
[&file]
{
if ( file.is_open() )
{
file.close();
}
} );

file.open(file_path.string(), std::ios::in);
if (!file.is_open()) {
Expand Down Expand Up @@ -293,7 +295,7 @@ namespace sgns::crypto {
}
}

return ED25519Keys(keys.begin(), keys.end());
return { keys.begin(), keys.end() };
}

CryptoStore::SR25519Keys CryptoStoreImpl::getSr25519PublicKeys(
Expand Down Expand Up @@ -340,7 +342,7 @@ namespace sgns::crypto {
}
}

return SR25519Keys(keys.begin(), keys.end());
return { keys.begin(), keys.end() };
}
} // namespace sgns::crypto

Expand Down
5 changes: 1 addition & 4 deletions src/crypto/crypto_store/crypto_store_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_CRYPTO_STORE_IMPL_HPP
#define SUPERGENIUS_CRYPTO_STORE_IMPL_HPP

Expand All @@ -15,7 +13,6 @@
#include "crypto/sr25519_provider.hpp"

namespace sgns::crypto {

namespace store {
using KeyPair = boost::variant<ED25519Keypair, SR25519Keypair>;
using PublicKey = base::Blob<32>;
Expand All @@ -42,7 +39,7 @@ namespace sgns::crypto {

inline std::ostream &operator<<(std::ostream &out, const CryptoStoreError &test_struct)
{
return out << (int)test_struct;
return out << static_cast<int>(test_struct);
}

class CryptoStoreImpl : public CryptoStore {
Expand Down
16 changes: 6 additions & 10 deletions src/crypto/crypto_store/key_type.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@


#ifndef SUPERGENIUS_CRYPTO_KEY_TYPE_HPP
#define SUPERGENIUS_CRYPTO_KEY_TYPE_HPP

#include "base/blob.hpp"
#include "outcome/outcome.hpp"

namespace sgns::crypto {

enum class KeyTypeError {
UNSUPPORTED_KEY_TYPE = 1,
UNSUPPORTED_KEY_TYPE_ID,
Expand All @@ -23,12 +19,12 @@ namespace sgns::crypto {
* Types are 32bit integers, which represent encoded 4-char strings
* Big-endian byte order is used
*/
static constexpr KeyTypeId kProd = 1886547812u; // "prod"
static constexpr KeyTypeId kGran = 1735549294u; // "gran"
static constexpr KeyTypeId kAcco = 1633903471u; // "acco"
static constexpr KeyTypeId kImon = 1768779630u; // "imon"
static constexpr KeyTypeId kAudi = 1635083369u; // "audi"
static constexpr KeyTypeId kLp2p = 1819292272u; // "lp2p"
static constexpr KeyTypeId kProd = 1886547812U; // "prod"
static constexpr KeyTypeId kGran = 1735549294U; // "gran"
static constexpr KeyTypeId kAcco = 1633903471U; // "acco"
static constexpr KeyTypeId kImon = 1768779630U; // "imon"
static constexpr KeyTypeId kAudi = 1635083369U; // "audi"
static constexpr KeyTypeId kLp2p = 1819292272U; // "lp2p"
} // namespace supported_key_types

/**
Expand Down
7 changes: 2 additions & 5 deletions src/crypto/ed25519/ed25519_provider_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP
#define SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP

#include "crypto/ed25519_provider.hpp"

namespace sgns::crypto {

class ED25519ProviderImpl : public ED25519Provider {
public:
~ED25519ProviderImpl() override = default;
Expand All @@ -30,6 +27,6 @@ namespace sgns::crypto {
}
};

} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_ED25519_PROVIDER_IMPL_HPP
#endif
7 changes: 2 additions & 5 deletions src/crypto/ed25519_provider.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP
#define SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP

Expand All @@ -9,7 +7,6 @@
#include "integration/IComponent.hpp"

namespace sgns::crypto {

enum class ED25519ProviderError {
FAILED_GENERATE_KEYPAIR = 1,
SIGN_UNKNOWN_ERROR, // unknown error occurred during call to `sign` method
Expand Down Expand Up @@ -55,8 +52,8 @@ namespace sgns::crypto {
gsl::span<uint8_t> message,
const ED25519PublicKey &public_key) const = 0;
};
} // namespace sgns::crypto
}

OUTCOME_HPP_DECLARE_ERROR_2(sgns::crypto, ED25519ProviderError)

#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_PROVIDER_HPP
#endif
4 changes: 1 addition & 3 deletions src/crypto/ed25519_types.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#include "ed25519_types.hpp"

namespace sgns::crypto {
Expand All @@ -10,4 +8,4 @@ namespace sgns::crypto {
bool ED25519Keypair::operator!=(const ED25519Keypair &other) const {
return !(*this == other);
}
} // namespace sgns::crypto
}
9 changes: 3 additions & 6 deletions src/crypto/ed25519_types.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP
#define SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP

Expand All @@ -8,7 +6,6 @@
#include "integration/IComponent.hpp"

namespace sgns::crypto {

namespace constants::ed25519 {
/**
* Important constants to deal with ed25519
Expand All @@ -19,7 +16,7 @@ namespace sgns::crypto {
SIGNATURE_SIZE = ed25519_signature_SIZE,
SEED_SIZE = PRIVKEY_SIZE,
};
} // namespace constants::ed25519
}

using ED25519PrivateKey = base::Blob<constants::ed25519::PRIVKEY_SIZE>;
using ED25519PublicKey = base::Blob<constants::ed25519::PUBKEY_SIZE>;
Expand Down Expand Up @@ -47,6 +44,6 @@ namespace sgns::crypto {
using ED25519Signature = base::Blob<constants::ed25519::SIGNATURE_SIZE>;

using ED25519Seed = base::Blob<constants::ed25519::SEED_SIZE>;
} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SRC_CRYPTO_ED25519_TYPES_HPP
#endif
6 changes: 2 additions & 4 deletions src/crypto/hasher.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_SRC_HASHER_HASHER_HPP_
#define SUPERGENIUS_SRC_HASHER_HASHER_HPP_

Expand Down Expand Up @@ -75,6 +73,6 @@ namespace sgns::crypto {
*/
[[nodiscard]] virtual Hash256 sha2_256( gsl::span<const uint8_t> buffer ) const = 0;
};
} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SRC_HASHER_HASHER_HPP_
#endif
5 changes: 1 addition & 4 deletions src/crypto/pbkdf2/impl/pbkdf2_provider_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@


#include "crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp"

#include <openssl/evp.h>

namespace sgns::crypto {

outcome::result<base::Buffer> Pbkdf2ProviderImpl::deriveKey(
gsl::span<const uint8_t> data,
gsl::span<const uint8_t> salt,
Expand All @@ -30,7 +27,7 @@ namespace sgns::crypto {

return out;
}
} // namespace sgns::crypto
}

OUTCOME_CPP_DEFINE_CATEGORY_3(sgns::crypto, Pbkdf2ProviderError, error) {
using Error = sgns::crypto::Pbkdf2ProviderError;
Expand Down
6 changes: 2 additions & 4 deletions src/crypto/pbkdf2/impl/pbkdf2_provider_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP
#define SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP

Expand All @@ -17,6 +15,6 @@ namespace sgns::crypto {
size_t key_length) const override;
};

} // namespace sgns::crypto
}

#endif // SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_IMPL_HPP
#endif
2 changes: 0 additions & 2 deletions src/crypto/pbkdf2/pbkdf2_provider.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_HPP
#define SUPERGENIUS_CRYPTO_PBKDF2_PROVIDER_HPP

Expand Down
6 changes: 2 additions & 4 deletions src/crypto/random_generator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP
#define SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP

Expand All @@ -8,6 +6,6 @@
namespace sgns::crypto {
using RandomGenerator = libp2p::crypto::random::RandomGenerator;
using CSPRNG = libp2p::crypto::random::CSPRNG;
} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_HPP
#endif
13 changes: 5 additions & 8 deletions src/crypto/random_generator/boost_generator.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@


#ifndef SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP
#define SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP

#include "libp2p/crypto/random_generator/boost_generator.hpp"

namespace sgns::crypto {

using BoostRandomGenerator = libp2p::crypto::random::BoostRandomGenerator;
using CSPRNG = libp2p::crypto::random::CSPRNG;

namespace sgns::crypto
{
using BoostRandomGenerator = libp2p::crypto::random::BoostRandomGenerator;
using CSPRNG = libp2p::crypto::random::CSPRNG;
}

#endif // SUPERGENIUS_SRC_CRYPTO_RANDOM_GENERATOR_BOOST_GENERATOR_HPP
#endif
6 changes: 2 additions & 4 deletions src/crypto/secp256k1/secp256k1_provider_impl.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP
#define SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP

Expand All @@ -7,7 +6,6 @@
#include "crypto/secp256k1_provider.hpp"

namespace sgns::crypto {

enum class Secp256k1ProviderError {
INVALID_ARGUMENT = 1,
INVALID_V_VALUE,
Expand Down Expand Up @@ -37,8 +35,8 @@ namespace sgns::crypto {

std::unique_ptr<secp256k1_context, void (*)(secp256k1_context *)> context_;
};
} // namespace sgns::crypto
}

OUTCOME_HPP_DECLARE_ERROR_2(sgns::crypto, Secp256k1ProviderError);

#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_IMPL_HPP
#endif
6 changes: 2 additions & 4 deletions src/crypto/secp256k1_provider.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

#ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP
#define SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP

#include "crypto/secp256k1_types.hpp"
#include "outcome/outcome.hpp"

namespace sgns::crypto {

/**
* @class Secp256k1Provider provides public key recovery functionality
*/
Expand Down Expand Up @@ -37,6 +35,6 @@ namespace sgns::crypto {
const secp256k1::MessageHash &message_hash) const = 0;
};

} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_PROVIDER_HPP
#endif
5 changes: 2 additions & 3 deletions src/crypto/secp256k1_types.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifndef SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP
#define SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP

Expand Down Expand Up @@ -44,6 +43,6 @@ namespace sgns::crypto::secp256k1 {
* 32-byte sequence of bytes (presumably blake2s hash)
*/
using MessageHash = base::Hash256;
} // namespace sgns::crypto::secp256k1
}

#endif // SUPERGENIUS_SRC_CRYPTO_SECP256K1_TYPES_HPP
#endif
6 changes: 2 additions & 4 deletions src/crypto/sha/sha256.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


#ifndef SUPERGENIUS_SHA256_HPP
#define SUPERGENIUS_SHA256_HPP

Expand All @@ -22,6 +20,6 @@ namespace sgns::crypto {
* @return hashed bytes
*/
base::Hash256 sha256(gsl::span<const uint8_t> input);
} // namespace sgns::crypto
}

#endif // SUPERGENIUS_SHA256_HPP
#endif
Loading

0 comments on commit c16e406

Please sign in to comment.