Kagome
Polkadot Runtime Engine in C++17
kagome::crypto::KeyFileStorage Class Reference

#include <key_file_storage.hpp>

Collaboration diagram for kagome::crypto::KeyFileStorage:

Public Types

enum  Error {
  Error::WRONG_KEYFILE_NAME = 1, Error::NOT_REGULAR_FILE, Error::FAILED_OPEN_FILE, Error::FILE_DOESNT_EXIST,
  Error::INVALID_FILE_FORMAT, Error::INCONSISTENT_KEYFILE, Error::KEYS_PATH_IS_NOT_DIRECTORY, Error::FAILED_CREATE_KEYS_DIRECTORY
}
 
using Buffer = common::Buffer
 
using Path = boost::filesystem::path
 

Public Member Functions

outcome::result< std::vector< Buffer > > collectPublicKeys (KeyTypeId type) const
 
outcome::result< std::optional< Buffer > > searchForSeed (KeyTypeId type, gsl::span< const uint8_t > public_key_bytes) const
 
outcome::result< void > saveKeyPair (KeyTypeId type, gsl::span< const uint8_t > public_key, gsl::span< const uint8_t > seed) const
 
outcome::result< std::string > loadFileContent (const Path &file_path) const
 
outcome::result< void > saveKeyHexAtPath (gsl::span< const uint8_t > private_key, const Path &path) const
 

Static Public Member Functions

static outcome::result< std::unique_ptr< KeyFileStorage > > createAt (Path keystore_path)
 

Private Member Functions

 KeyFileStorage (Path keystore_path)
 
outcome::result< void > initialize ()
 
outcome::result< std::pair< KeyTypeId, Buffer > > parseKeyFileName (std::string_view file_name) const
 
Path composeKeyPath (KeyTypeId key_type, gsl::span< const uint8_t > public_key) const
 

Private Attributes

Path keystore_path_
 
log::Logger logger_
 

Detailed Description

Class for operations over key storage in file system

Definition at line 23 of file key_file_storage.hpp.

Member Typedef Documentation

using kagome::crypto::KeyFileStorage::Path = boost::filesystem::path

Definition at line 37 of file key_file_storage.hpp.

Member Enumeration Documentation

Enumerator
WRONG_KEYFILE_NAME 
NOT_REGULAR_FILE 
FAILED_OPEN_FILE 
FILE_DOESNT_EXIST 
INVALID_FILE_FORMAT 
INCONSISTENT_KEYFILE 
KEYS_PATH_IS_NOT_DIRECTORY 
FAILED_CREATE_KEYS_DIRECTORY 

Definition at line 25 of file key_file_storage.hpp.

Constructor & Destructor Documentation

kagome::crypto::KeyFileStorage::KeyFileStorage ( Path  keystore_path)
explicitprivate

Definition at line 45 of file key_file_storage.cpp.

Member Function Documentation

outcome::result< std::vector< Buffer > > kagome::crypto::KeyFileStorage::collectPublicKeys ( KeyTypeId  type) const

Collects all public keys of the given type from the key storage

Definition at line 154 of file key_file_storage.cpp.

KeyFileStorage::Path kagome::crypto::KeyFileStorage::composeKeyPath ( KeyTypeId  key_type,
gsl::span< const uint8_t >  public_key 
) const
private

Definition at line 70 of file key_file_storage.cpp.

outcome::result< std::unique_ptr< KeyFileStorage > > kagome::crypto::KeyFileStorage::createAt ( Path  keystore_path)
static

Initializes key storage at the given

Parameters
keystore_path.Creates its dir if it doesn't exist, but won't create missing parent dirs

TODO(Harrm): add enforcement of key file permissions (like in SSH)

Definition at line 38 of file key_file_storage.cpp.

outcome::result< void > kagome::crypto::KeyFileStorage::initialize ( )
private

Definition at line 91 of file key_file_storage.cpp.

outcome::result< std::string > kagome::crypto::KeyFileStorage::loadFileContent ( const Path file_path) const

Load key file contents without validation. The file may not exist. Used when –node-key-file flag is specified.

Parameters
file_path- path to the key. The contents are raw-bytes or hex-encoded key
Returns
file contents. Format interpreting is up to the caller

Definition at line 121 of file key_file_storage.cpp.

outcome::result< std::pair< KeyTypeId, Buffer > > kagome::crypto::KeyFileStorage::parseKeyFileName ( std::string_view  file_name) const
private

Definition at line 50 of file key_file_storage.cpp.

outcome::result< void > kagome::crypto::KeyFileStorage::saveKeyHexAtPath ( gsl::span< const uint8_t >  private_key,
const Path path 
) const

Save key as hex to the specific path. Used when –node-key-file flag is specified.

Parameters
key_bytes- key contents to save
file_path- user-provided path to create the file
Returns
an error if any

Definition at line 140 of file key_file_storage.cpp.

outcome::result< void > kagome::crypto::KeyFileStorage::saveKeyPair ( KeyTypeId  type,
gsl::span< const uint8_t >  public_key,
gsl::span< const uint8_t >  seed 
) const

Stores the

Parameters
seedthat generates the
public_keyto the key storage

Definition at line 78 of file key_file_storage.cpp.

outcome::result< std::optional< Buffer > > kagome::crypto::KeyFileStorage::searchForSeed ( KeyTypeId  type,
gsl::span< const uint8_t >  public_key_bytes 
) const

Searches for a key file for the corresponding type and public key and returns its content if it's a valid hex number

Definition at line 184 of file key_file_storage.cpp.

Member Data Documentation

Path kagome::crypto::KeyFileStorage::keystore_path_
private

Definition at line 99 of file key_file_storage.hpp.

log::Logger kagome::crypto::KeyFileStorage::logger_
private

Definition at line 100 of file key_file_storage.hpp.


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