Back to Site
Loading...
Searching...
No Matches
librats::PeerId Class Reference

#include <peer_id.h>

Classes

struct  Hash
 Hash functor for use as an unordered_map/set key. More...
 

Public Member Functions

 PeerId ()=default
 
std::string to_hex () const
 
std::string short_hex () const
 first 8 hex chars, for logs
 
const std::array< uint8_t, kSize > & bytes () const noexcept
 
bool is_zero () const noexcept
 
bool operator== (const PeerId &o) const noexcept
 
bool operator!= (const PeerId &o) const noexcept
 
bool operator< (const PeerId &o) const noexcept
 

Static Public Member Functions

static PeerId from_public_key (const uint8_t *key, size_t len)
 Derive the PeerId from a raw static public key (SHA-256 of the key).
 
static PeerId from_public_key (ByteView key)
 
static std::optional< PeerIdfrom_bytes (ByteView raw)
 Wrap raw 32 id-bytes verbatim (NOT hashed). nullopt unless exactly kSize.
 
static std::optional< PeerIdfrom_hex (std::string_view hex)
 Parse a 64-char lowercase/uppercase hex string. nullopt if malformed.
 

Static Public Attributes

static constexpr size_t kSize = 32
 SHA-256 digest length.
 

Detailed Description

Definition at line 26 of file peer_id.h.

Constructor & Destructor Documentation

◆ PeerId()

librats::PeerId::PeerId ( )
default

Member Function Documentation

◆ bytes()

const std::array< uint8_t, kSize > & librats::PeerId::bytes ( ) const
inlinenoexcept

Definition at line 45 of file peer_id.h.

◆ from_bytes()

static std::optional< PeerId > librats::PeerId::from_bytes ( ByteView  raw)
static

Wrap raw 32 id-bytes verbatim (NOT hashed). nullopt unless exactly kSize.

◆ from_hex()

static std::optional< PeerId > librats::PeerId::from_hex ( std::string_view  hex)
static

Parse a 64-char lowercase/uppercase hex string. nullopt if malformed.

◆ from_public_key() [1/2]

static PeerId librats::PeerId::from_public_key ( ByteView  key)
inlinestatic

Definition at line 34 of file peer_id.h.

References from_public_key().

Referenced by from_public_key().

◆ from_public_key() [2/2]

static PeerId librats::PeerId::from_public_key ( const uint8_t *  key,
size_t  len 
)
static

Derive the PeerId from a raw static public key (SHA-256 of the key).

◆ is_zero()

bool librats::PeerId::is_zero ( ) const
noexcept

◆ operator!=()

bool librats::PeerId::operator!= ( const PeerId o) const
inlinenoexcept

Definition at line 49 of file peer_id.h.

◆ operator<()

bool librats::PeerId::operator< ( const PeerId o) const
inlinenoexcept

Definition at line 50 of file peer_id.h.

◆ operator==()

bool librats::PeerId::operator== ( const PeerId o) const
inlinenoexcept

Definition at line 48 of file peer_id.h.

◆ short_hex()

std::string librats::PeerId::short_hex ( ) const

first 8 hex chars, for logs

◆ to_hex()

std::string librats::PeerId::to_hex ( ) const

Member Data Documentation

◆ kSize

constexpr size_t librats::PeerId::kSize = 32
staticconstexpr

SHA-256 digest length.

Definition at line 28 of file peer_id.h.


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