alpine-protocol-sdk 0.2.2

High-level SDK on top of the ALPINE protocol layer.
Documentation
use alpine::handshake::HandshakeError;
use alpine::stream::StreamError;
use thiserror::Error;

use crate::transport::TransportError;

/// Errors emitted by the SDK runtime.
#[derive(Error, Debug)]
pub enum AlpineSdkError {
    #[error("transport error: {0}")]
    Transport(#[from] TransportError),

    #[error("connection timed out")]
    Timeout,

    #[error("discovery failed: {0}")]
    DiscoveryFailed(String),

    #[error("invalid discovery reply")]
    InvalidDiscoveryReply,

    #[error("handshake already in progress")]
    HandshakeAlreadyInProgress,

    #[error("discovery not allowed once handshake has begun")]
    DiscoveryAfterHandshake,

    #[error("invalid phase transition: {0}")]
    InvalidPhaseTransition(String),

    #[error("missing client_nonce")]
    MissingClientNonce,

    #[error("handshake failed: {0}")]
    HandshakeFailed(String),

    #[error("device identity verification failed")]
    IdentityVerificationFailed,

    #[error("io error: {0}")]
    Io(String),

    #[error("no active session")]
    NoActiveSession,

    #[error("session expired")]
    SessionExpired,

    #[error("streaming not supported by device")]
    StreamingNotSupported,

    #[error("invalid channel value")]
    InvalidChannelValue,

    #[error("internal error: {0}")]
    Internal(String),
}

impl From<HandshakeError> for AlpineSdkError {
    fn from(err: HandshakeError) -> Self {
        match err {
            HandshakeError::Transport(_) => AlpineSdkError::HandshakeFailed(err.to_string()),
            other => AlpineSdkError::HandshakeFailed(other.to_string()),
        }
    }
}

impl From<StreamError> for AlpineSdkError {
    fn from(err: StreamError) -> Self {
        AlpineSdkError::Internal(err.to_string())
    }
}