Binary Field Encodings (BFE) for Secure Scuttlebutt (SSB)

Overview

ssb-bfe-rs

Binary Field Encodings (BFE) for Secure Scuttlebutt (SSB).

Based on the JavaScript reference implementation: ssb-bfe (written according to the specification).

While encode() and decode() are the two primary functions exposed by this crate, the various helper functions and values are also exported for public use.

Encode

The encoder expects JSON input in the form of a serde_json::Value enum. The encoded value is returned as an BfeValue (a custom enum provided by this library).

Decode

The decoder expects input in the form of an BfeValue (a custom enum provided by this library). The decoded value is returned as JSON in the form of a serde_json::Value enum.

Deserialize and Serialize traits have been derived for BfeValue, meaning that encoded JSON objects can be parsed into the BfeValue type if required (for example, if the value is received as a byte slice of serialized JSON data). See the serde documentation on Parsing JSON as strongly typed data structures for an example and further explanation.

Example

use ssb_bfe_rs;
use serde_json::json;

let value = json!({
    "author": "@6CAxOI3f+LUOVrbAl0IemqiS7ATpQvr9Mdw9LC4+Uv0=.bbfeed-v1",
    "previous": "%R8heq/tQoxEIPkWf0Kxn1nCm/CsxG2CDpUYnAvdbXY8=.bbmsg-v1"
});

let encoded = ssb_bfe_rs::encode(&value)?;
println!("{:X?}", encoded);

// Object({"author": Buffer([0, 3, E8, 20, 31, 38, 8D, DF, F8, B5, E, 56, B6, C0, 97, 42, 1E, 9A, A8, 92, EC, 4, E9, 42, FA, FD, 31, DC, 3D, 2C, 2E, 3E, 52, FD]), "previous": Buffer([1, 4, 47, C8, 5E, AB, FB, 50, A3, 11, 8, 3E, 45, 9F, D0, AC, 67, D6, 70, A6, FC, 2B, 31, 1B, 60, 83, A5, 46, 27, 2, F7, 5B, 5D, 8F])})

let decoded = ssb_bfe_rs::decode(&encoded_value)?;
println!("{:?}", decoded);

// Object({"author": String("@6CAxOI3f+LUOVrbAl0IemqiS7ATpQvr9Mdw9LC4+Uv0=.bbfeed-v1"), "previous": String("%R8heq/tQoxEIPkWf0Kxn1nCm/CsxG2CDpUYnAvdbXY8=.bbmsg-v1")})

Documentation

Use cargo doc to generate and serve the Rust documentation for this library:

git clone [email protected]:ssb-ngi-pointer/ssb-bfe-rs.git
cd ssb-bfe-rs
cargo doc --no-deps --open 

License

LGPL-3.0.

Comments
  • Return buf un(en|de)coded

    Return buf un(en|de)coded

    An unmatched buffer value (Vec<u8) was previously being base64 encoded before being returned as JSON from the decode() function. This PR removes the encoding step and wraps the bytes in an object (to match the shape of JSON-encoded Buffers).

    Also added a test to ensure the correct value is returned in such a case.

    Also added a test to ensure correct blob encode -> decode.

    opened by mycognosist 2
  • Support encoding and decoding of SSB URIs

    Support encoding and decoding of SSB URIs

    • [x] add spec data for all type-formats
    • [x] add uri encoding
    • [x] add uri decoding
    • [x] update tests to use uris
    • [x] ensure documentation examples are up to date
    • [x] publish ssb-uri-rs version 0.1.3
      • [x] depends on https://github.com/ssb-ngi-pointer/ssb-uri-rs/pull/5
    • [x] bump dependency versions (ssb-uri-rs)
    • [x] bump crate version

    encode_uri() is not as elegant as I'd like but I'll loop back to it and refactor at some point.

    opened by mycognosist 1
  • Add support for blobs and numbers (plus general refactor)

    Add support for blobs and numbers (plus general refactor)

    • Add support for bypassing / returning numbers (integers and float)
    • Add support for blobs
    • Rename constants to be consistent with JS implementation
    • Rewrite (most) error messages to be consistent with JS implementation

    There will be more refactors, tests and doc updates in the coming days.

    opened by mycognosist 0
  • Add box support

    Add box support

    • Add encode / decode support for encrypted (.box) messages (classic type : .box and box2 : .box2)
    • Add tests

    Diff is noisy due to reshuffle of functions (A-Z all the things).

    enhancement 
    opened by mycognosist 0
  • Implement decoder

    Implement decoder

    • Add decode() capability and helper functions
    • Remove regex and lazy_static dependencies
      • Perform string manipulations using standard library features (ie. .rfind() and .strip_suffix())
    • Rename ConvertedValue enum to EncodedValue
      • Rename variants to match JS expectations (Array, Buffer, Object)
      • Replace HashMap with IndexMap to preserve field order in key-value objects
    • Add a test to encode and decode a heterogeneous JSON object

    More tests and docs tomorrow.

    enhancement 
    opened by mycognosist 0
Owner
SSB team in pointer.ngi.eu
null
Easy access of struct fields in strings using different/custom pre/postfix: "Hello, {field}" in rust

Easy access to struct fields in strings ?? add strung to the dependencies in the Cargo.toml: [dependencies] strung = "0.1.3" ?? use/import everything

Dekirisu 2 Sep 19, 2022
Statically verified Rust struct field names as strings.

field Statically verified struct field names as strings. See the documentation for more details. Installation Add the following to your Cargo manifest

Indraneel Mahendrakumar 3 Jul 9, 2023
Build light & secure cross-platform applications with a web-based UI

Millennium Icon by XFaon. *Stats are from Tauri and may not be fully accurate. Millennium is a cross-platform webview framework written in Rust. With

pyke 20 Dec 29, 2022
A user-friendly TUI for secure file transfers, with arrow-key and VIM-style navigation

gsftp SFTP with an interactive text-based user interface (TUI). Transfer files through an encrypted connection with a visual interface, so you can see

Ben Jiron 3 Jul 7, 2022
Secure Boot for NixOS [maintainers=@blitz @raitobezarius @nikstur]

Lanzaboote: Secure Boot for NixOS This repository contains tooling for UEFI Secure Boot on NixOS. The goal is to make Secure Boot available from nixpk

Nix community projects 79 Jan 6, 2023
(Pre-Release Software) Secure, Encrypted, P2P chat written atop Warp, IPFS, LibP2P, Dioxus and many more awesome projects and protocols.

Uplink Privacy First, Modular, P2P messaging client built atop Warp. Uplink is written in pure Rust with a UI in Dioxus (which is also written in Rust

Satellite 13 Jan 25, 2023
Cuprate, an upcoming experimental, modern & secure monero node. Written in Rust

Cuprate an upcoming experimental, modern & secure monero node. Written in Rust (there is nothing working at the moment, stay tuned if you want to see

Someone Else 16 Feb 20, 2023
COCONUT Secure VM Service Module

This is the source code repository for the COCONUT Secure VM Service Module (SVSM), a software which aims to provide secure services and device emulations to guest operating systems in confidential virtual machines (CVMs). It requires AMD Secure Encrypted Virtualization with Secure Nested Paging (AMD SEV-SNP), especially the VM Privilege Level (VMPL) feature.

null 15 Mar 28, 2023
A Modern And Secure CLI Tool For Managing Environment Variables

Envio is a command-line tool that simplifies the management of environment variables across multiple profiles. It allows users to easily switch between different configurations and apply them to their current environment

Humble Penguin 536 Apr 16, 2023
Simple Secure Static (HTTPS) File Server with embedded certificate

Secure Static File Server Static Files HTTPs server with self signed embedded certificate Installation Install using cargo: cargo install ssfs Or buil

0xor0ne 21 Apr 20, 2023
A secure CLI password generator written in rust.

Rust CLI Password Generator Overview This Project is a secure CLI password generator written in rust. This generates a secure password with three diff

pouyan shalbafan 12 Nov 9, 2023
Download binary for your OS from Github

github-bin-downloader Download binary for your OS from Github. Installation Install github-bin-downloader using cargo cargo install github-bin-downloa

353fc443 10 Dec 11, 2022
Non-Recursive Inverting of Binary Tree in Rust

Non-Recursive Inverting of Binary Tree in Rust The idea is to implement the classical Inverting of Binary Tree but without using recursion. Quick Star

Tsoding 15 Dec 6, 2022
1 library and 2 binary crates to run SSH/SCP commands on a "mass" of hosts in parallel

massh 1 library and 2 binary crates to run SSH/SCP commands on a "mass" of hosts in parallel. The binary crates are CLI and GUI "frontends" for the li

null 2 Oct 16, 2022
zman is a CLI year (time) progress that small, fast, and just one single binary.

zman zman is a CLI year (time) progress that small, fast, and just one single binary. Features Show year progress Show month, and week progress Show r

azzamsa 17 Dec 21, 2022
A rust binary that will flip one or more bits of a file (mostly for messing with images for fun).

file-bitflipper A rust binary that will flip one or more bits of a file (mostly for messing with images for fun). Example (bitflipped bentley) Usage $

null 1 Aug 31, 2022
🦀️atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols.

atosl-rs ??️ atos for linux by rust - A partial replacement for Apple's atos tool for converting addresses within a binary file to symbols. tested on

everettjf 60 Dec 29, 2022
Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux.

Load Symbols Binary Ninja plugin written in Rust to automatically apply symbol information from split debug info on Linux. Requirements Last tested wi

null 4 Jul 20, 2022
Databento Binary Encoding (DBZ) - Fast message encoding and storage format for market data

dbz A library (dbz-lib) and CLI tool (dbz-cli) for working with Databento Binary Encoding (DBZ) files. Python bindings for dbz-lib are provided in the

Databento, Inc. 15 Nov 4, 2022