Crate codec_sv2

Source
Expand description

§Stratum V2 Codec Library

codec_sv2 provides the message encoding and decoding functionality for the Stratum V2 (Sv2) protocol, handling secure communication between Sv2 roles.

This crate abstracts the complexity of message encoding/decoding with optional Noise protocol support, ensuring both regular and encrypted messages can be serialized, transmitted, and decoded consistently and reliably.

§Usage

codec-sv2 supports both standard Sv2 frames (unencrypted) and Noise-encrypted Sv2 frames to ensure secure communication. To encode messages for transmission, choose between the Encoder for standard Sv2 frames or the NoiseEncoder for encrypted frames. To decode received messages, choose between the StandardDecoder for standard Sv2 frames or StandardNoiseDecoder to decrypt Noise frames.

§Build Options

This crate can be built with the following features:

  • std: Enable usage of rust std library, enabled by default.
  • noise_sv2: Enables support for Noise protocol encryption and decryption.
  • with_buffer_pool: Enables buffer pooling for more efficient memory management.

In order to use this crate in a #![no_std] environment, use the --no-default-features to remove the std feature.

§Examples

See the examples for more information:

Re-exports§

pub use error::CError;
pub use error::Error;
pub use error::Result;
pub use noise_sv2;
pub use buffer_sv2;
pub use binary_sv2;
pub use framing_sv2;

Modules§

error
Error Handling and Result Types

Structs§

Encoder
Encoder for standard Sv2 frames.
HandShakeFrame
Abstraction for a Noise handshake frame.
Initiator
Manages the initiator’s role in the Noise NX handshake, handling key exchange, encryption, and handshake state. It securely generates and manages cryptographic keys, performs Diffie-Hellman exchanges, and maintains the handshake hash, chaining key, and nonce for message encryption. After the handshake, it facilitates secure communication using either ChaCha20Poly1305 or AES-GCM ciphers. Sensitive data is securely erased when no longer needed.
NoiseCodec
A codec for managing encrypted communication in the Noise protocol.
NoiseEncoder
Encoder for Sv2 frames with Noise protocol encryption.
Responder
Represents the state and operations of the responder in the Noise NX protocol handshake. It handles cryptographic key exchanges, manages handshake state, and securely establishes a connection with the initiator. The responder manages key generation, Diffie-Hellman exchanges, message decryption, and state transitions, ensuring secure communication. Sensitive cryptographic material is securely erased when no longer needed.
Sv2Frame
Abstraction for a Sv2 frame.

Enums§

Frame
Represents either an Sv2 frame or a handshake frame.
HandshakeRole
Represents the role in the Noise handshake process, either as an initiator or a responder.
State
Represents the state of the Noise protocol codec during different phases: initialization, handshake, or transport mode, where encryption and decryption are fully operational.

Functions§

h2f
Returns a HandShakeFrame from a generic byte array.

Type Aliases§

StandardDecoder
Standard Sv2 decoder without Noise protocol support.
StandardEitherFrame
An encoded or decoded Sv2 frame containing either a regular or Noise-protected message.
StandardNoiseDecoder
Standard Sv2 decoder with Noise protocol support.
StandardSv2Frame
An encoded or decoded Sv2 frame.