From 41665ea30b20c4a92454dfcc4a6f3557a47e1d3b Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Sun, 29 Jun 2025 17:39:20 +0100 Subject: [PATCH] Added executable, added B64 encoding Signed-off-by: Louis Hollingworth --- Cargo.lock | 11 ++++- Cargo.toml | 6 ++- flake.lock | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 32 +++++++++++++ src/bin/suid.rs | 7 +++ src/lib.rs | 6 +++ 6 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/bin/suid.rs diff --git a/Cargo.lock b/Cargo.lock index c25f598..596b664 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,12 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "cfg-if" @@ -93,8 +99,9 @@ dependencies = [ [[package]] name = "suid" -version = "0.2.0" +version = "0.3.0" dependencies = [ + "base64", "rand", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index 1dedda4..2fd7e9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "suid" -version = "0.2.0" +version = "0.3.0" edition = "2021" publish = ["ludogit"] authors = ["Louis Hollingworth "] @@ -9,6 +9,10 @@ readme = "README.md" repository = "https://git.ludoviko.ch/lucxjo/suid" license = "AGPL-3.0-or-later" +[[bin]] +name = "suid" + [dependencies] +base64 = "0.22.1" rand = "0.8.5" tracing = "0.1.40" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a18e8e8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,116 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1750266157, + "narHash": "sha256-tL42YoNg9y30u7zAqtoGDNdTyXTi8EALDeCB13FtbQA=", + "owner": "ipetkov", + "repo": "crane", + "rev": "e37c943371b73ed87faf33f7583860f81f1d5a48", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1751179326, + "narHash": "sha256-yBB9+MeXhi+g2Bb66WUuhSEzxRiqI/YbxWL+PvJnmCw=", + "owner": "nix-community", + "repo": "fenix", + "rev": "572e4e6540941475a7606aea12b104fe496bb322", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1751011381, + "narHash": "sha256-krGXKxvkBhnrSC/kGBmg5MyupUUT5R6IBCLEzx9jhMM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "30e2e2857ba47844aa71991daa6ed1fc678bcbb7", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1751104482, + "narHash": "sha256-jIYKLyOVBR8hlq9Vap9VEQ+sYVMuBu/7humjtGzxUuk=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "13ffda70eb4e357344e55d996889ea43d51041cd", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8ac21f3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,32 @@ +{ + description = "A very basic flake"; + + inputs = { + flake-utils = { + url = "github:numtide/flake-utils"; + }; + crane.url = "github:ipetkov/crane"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + }; + + outputs = inputs: + with inputs; + flake-utils.lib.eachDefaultSystem ( + system: let + pkgs = import nixpkgs { + inherit system; + }; + rustPkgs = (crane.mkLib pkgs).overrideToolchain + fenix.packages.${system}.beta.toolchain; + in { + packages = { + default = rustPkgs.buildPackage { + src = rustPkgs.cleanCargoSource ./.; + }; + }; + }); +} diff --git a/src/bin/suid.rs b/src/bin/suid.rs new file mode 100644 index 0000000..7aa2a1d --- /dev/null +++ b/src/bin/suid.rs @@ -0,0 +1,7 @@ +use suid::SUID; + +fn main() { + let suid = SUID::new(); + println!("Hex: {}", suid.as_string()); + println!("B64: {}", suid.as_base64()); +} diff --git a/src/lib.rs b/src/lib.rs index 0ea4404..a3ef0aa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +use base64::prelude::*; + const BYTE_LENGTH: usize = 20; pub type Bytes = [u8; BYTE_LENGTH]; @@ -46,4 +48,8 @@ impl SUID { return string; } + pub fn as_base64(self) -> String { + let b64 = BASE64_URL_SAFE.encode(self.as_string()); + return b64; + } }