Skip to main content

Crate shardline_protocol

Crate shardline_protocol 

Source
Expand description

Shared protocol-facing types used by Shardline clients, storage adapters, and the HTTP server.

This crate keeps the wire-level contracts small and explicit:

  • ShardlineHash stores validated 32-byte hashes and canonical lowercase hexadecimal text.
  • ByteRange and ChunkRange validate range boundaries before they reach storage code.
  • TokenSigner signs and verifies scoped bearer tokens without exposing secret material in debug output.
  • RepositoryScope ties provider-issued tokens to one repository and, optionally, one revision.

§Example

use shardline_protocol::{
    RepositoryProvider, RepositoryScope, TokenClaims, TokenScope, TokenSigner,
};

let repository =
    RepositoryScope::new(RepositoryProvider::GitHub, "acme", "assets", Some("main"))?;
let claims = TokenClaims::new(
    "shardline",
    "alice",
    TokenScope::Read,
    repository,
    1_700_000_600,
)?;

let signer = TokenSigner::new(b"development-only-signing-key-32bytes")?;
let token = signer.sign(&claims)?;
let verified = signer.verify_at(&token, 1_700_000_000)?;

assert_eq!(verified.subject(), "alice");
assert_eq!(verified.repository().owner(), "acme");
assert!(verified.scope().allows_read());

Structs§

ByteRange
Inclusive byte range.
ChunkRange
End-exclusive chunk index range.
RepositoryScope
Repository and revision scope encoded into a token.
SecretBytes
Zeroizing byte-oriented secret material.
SecretString
Zeroizing UTF-8 secret material.
ShardlineHash
A 32-byte protocol hash.
TokenClaims
Signed token claims used by the Shardline API.
TokenSigner
Local token signer and verifier.

Enums§

HashParseError
Hash parsing failure.
HttpRangeParseError
Reconstruction request range parse failure.
RangeError
Range construction failure.
RepositoryProvider
Provider family encoded into a scoped token.
TokenClaimsError
Token claim validation failure.
TokenCodecError
Token signing or verification failure.
TokenScope
CAS token scope.

Functions§

parse_bool
Parses a boolean value from common operator-friendly strings.
parse_http_byte_range
Parses a reconstruction Range header into an inclusive byte range.
unix_now_seconds_lossy
Returns the current Unix timestamp in seconds.