Crate sigserlic

Source
Expand description

The signify serde license system.

Rust library to combine serde with libsignify. Based on openbsd signify.

§Quickstart

§Generate or import a key

use sigserlic::SigningKey;

// Generate
type Comment = (); // This key will not have a comment
let key = SigningKey::<Comment>::generate();

// Import an existing key (here encoded in json)
let json = r#"{
  "secret_key": "RWRCSwAAAADSJSpBLNHNIzTs0FMnX7paPcnmr795lupZeb8cfPFAOqtZeVxFArUaQirh3mbooWQkKXzG8pxBJ9Phf24z0b1QYYp6GWtCHbEYK7PUbXVsv6tU4lS3MH5sylrYLGdOcRs=",
  "created_at": "2024-12-24T15:02:48.845298Z",
  "expired_at": null,
  "comment": "testing key, do not use"
}"#;
let key: SigningKey<String> = serde_json::from_str(json).unwrap();

§Extract public key from signing key

use sigserlic::PublicKey;
let public_key = PublicKey::from(key);

assert_eq!(serde_json::to_string_pretty(&public_key).unwrap(), r#"{
  "public_key": "RWRZeb8cfPFAOmGKehlrQh2xGCuz1G11bL+rVOJUtzB+bMpa2CxnTnEb",
  "created_at": "2024-12-24T15:02:48.845298Z",
  "expired_at": null,
  "comment": "testing key, do not use"
}"#);

§Sign data, create a signature

#[derive(serde::Serialize, serde::Deserialize)]
struct MyMessage {
    string: String,
    bytes: Vec<u8>,
    int: i32,
    boolean: bool,
}
let message = MyMessage {
    string: "Toto mange du gateau".into(),
    bytes: vec![0xde, 0xad, 0xba, 0xed],
    int: -1,
    boolean: true,
};

type Comment = String;
let comment: Comment = "anybody can change me :)".into();

// Prepare data to be signed
type MySignatureBuilder = sigserlic::SignatureBuilder<MyMessage, Comment>;
let builder = MySignatureBuilder::new(message).comment(comment);

// You can set the timestamp and the expiration if you want
let builder = builder.timestamp(1735311570).unwrap();
let builder = builder.expiration(1735397970).unwrap();

// Let's sign our message!
let signature = key.sign(builder).unwrap();
assert_eq!(serde_json::to_string_pretty(&signature).unwrap(), r#"{
  "signed_artifact": {
    "data": {
      "string": "Toto mange du gateau",
      "bytes": [
        222,
        173,
        186,
        237
      ],
      "int": -1,
      "boolean": true
    },
    "timestamp": "2024-12-27T14:59:30Z",
    "expiration": "2024-12-28T14:59:30Z"
  },
  "signature": "RWRZeb8cfPFAOouGiUofEwLJ20MoKD3jG7FpIsNYFMlATrJL/Pdk0Muag+QMa2CLLecQV1Ycho6Ui3QjicTyxTcF68oDAIrnlQo=",
  "comment": "anybody can change me :)"
}"#);

§Verify data, get original data

// Define what are the used types in this signature
type MySignature = sigserlic::Signature<MyMessage, Comment>;
let signature: MySignature = serde_json::from_str(json).unwrap();
    "public_key": "RWRZeb8cfPFAOmGKehlrQh2xGCuz1G11bL+rVOJUtzB+bMpa2CxnTnEb",

// Let's verify the signature with our public key, and get the signed message!
let message = signature.verify(&public_key).unwrap();

// Now we can finally get the original data
let data: &MyMessage = message.data();
assert_eq!(data.string, "Toto mange du gateau");

Modules§

error
Error which can occur when using the crate

Structs§

Message
Content signed by a SigningKey
PublicKey
A key with the capability of verifying a Signature emitted by a SigningKey.
Signature
Content produced by SignatureBuilder, signed by a SigningKey
SignatureBuilder
Temporary structure holding data waiting to be signed
SigningKey
A key with the capability of signing data, producing a Signature, which can be verified by a PublicKey.

Enums§

KeyUsage
What is the purpose of a key

Traits§

KeyMetadata
Metadata to identify keys