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< PeerId > from_bytes (ByteView raw)
 Wrap raw 32 id-bytes verbatim (NOT hashed). nullopt unless exactly kSize.
static std::optional< PeerId > from_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 27 of file peer_id.h.

Constructor & Destructor Documentation

◆ PeerId()

Member Function Documentation

◆ bytes()

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

Definition at line 46 of file peer_id.h.

◆ from_bytes()

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

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

◆ from_hex()

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]

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

Definition at line 35 of file peer_id.h.

References PeerId(), librats::ByteView::data(), from_public_key(), and librats::ByteView::size().

Referenced by from_public_key().

◆ from_public_key() [2/2]

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).

References PeerId().

◆ is_zero()

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

◆ operator!=()

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

Definition at line 50 of file peer_id.h.

References PeerId().

◆ operator<()

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

Definition at line 51 of file peer_id.h.

References PeerId().

◆ operator==()

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

Definition at line 49 of file peer_id.h.

References PeerId().

◆ 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

size_t librats::PeerId::kSize = 32
staticconstexpr

SHA-256 digest length.

Definition at line 29 of file peer_id.h.


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