feat: change to schema

This commit is contained in:
2023-11-26 15:41:20 +08:00
parent 99d478def5
commit bb10a24693

View File

@@ -14,7 +14,7 @@ use crate::digest::sha256_bytes;
use crate::util::base64_encode; use crate::util::base64_encode;
pub const SIMPLE_SIG_V1: &str = "v1"; pub const SIMPLE_SIG_V1: &str = "v1";
pub const SIMPLE_SIG_SPECIFICATION: &str = "https://openwebstandard.org/simple-sign-file/v1"; pub const SIMPLE_SIG_SCHEMA: &str = "https://openwebstandard.org/simple-sign-file/v1";
pub const HASH_ALGORITHM_SHA256: &str = "sha256"; pub const HASH_ALGORITHM_SHA256: &str = "sha256";
pub const SIGNATURE_ALGORITHM_SHA256_WITH_ECDSA: &str = "SHA256withECDSA"; pub const SIGNATURE_ALGORITHM_SHA256_WITH_ECDSA: &str = "SHA256withECDSA";
pub const CERTIFICATES_SEARCH_URL: &str = "https://hatter.ink/ca/fetch_certificates.json?fingerprint="; pub const CERTIFICATES_SEARCH_URL: &str = "https://hatter.ink/ca/fetch_certificates.json?fingerprint=";
@@ -111,7 +111,7 @@ pub struct SimpleSignFileSignature {
#[derive(Serialize)] #[derive(Serialize)]
pub struct SimpleSignFile { pub struct SimpleSignFile {
pub specification: String, pub schema: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub filename: Option<String>, pub filename: Option<String>,
pub digest: String, pub digest: String,
@@ -127,7 +127,7 @@ pub struct CommandImpl;
// Format: // Format:
// { // {
// "specification": "https://openwebstandard.org/simple-sign-file/v1", // "schema": "https://openwebstandard.org/simple-sign-file/v1",
// "version": "v1", // "version": "v1",
// "filename": "example.zip", // "filename": "example.zip",
// "digest": "sha256-HEX(SHA256(filename-content))", // "digest": "sha256-HEX(SHA256(filename-content))",
@@ -149,7 +149,8 @@ impl Command for CommandImpl {
fn subcommand<'a>(&self) -> App<'a, 'a> { fn subcommand<'a>(&self) -> App<'a, 'a> {
SubCommand::with_name(self.name()).about("PIV Sign(with SHA256) subcommand") SubCommand::with_name(self.name()).about("PIV Sign(with SHA256) subcommand")
.arg(Arg::with_name("pin").short("p").long("pin").takes_value(true).help("PIV card user pin")) .arg(Arg::with_name("pin").short("p").long("pin").takes_value(true).help("PIV card user pin"))
.arg(Arg::with_name("slot").short("s").long("slot").takes_value(true).required(true).help("PIV slot, e.g. 82, 83 ... 95, 9a, 9c, 9d, 9e")) .arg(Arg::with_name("slot").short("s").long("slot")
.takes_value(true).required(true).help("PIV slot, e.g. 82, 83 ... 95, 9a, 9c, 9d, 9e"))
.arg(Arg::with_name("file").short("f").long("file").takes_value(true).required(true).help("Input file")) .arg(Arg::with_name("file").short("f").long("file").takes_value(true).required(true).help("Input file"))
.arg(Arg::with_name("filename").short("n").long("filename").takes_value(true).help("Filename")) .arg(Arg::with_name("filename").short("n").long("filename").takes_value(true).help("Filename"))
.arg(Arg::with_name("comment").short("c").long("comment").takes_value(true).help("Comment")) .arg(Arg::with_name("comment").short("c").long("comment").takes_value(true).help("Comment"))
@@ -214,7 +215,7 @@ impl Command for CommandImpl {
certificates, certificates,
}; };
let simple_sig = SimpleSignFile { let simple_sig = SimpleSignFile {
specification: SIMPLE_SIG_SPECIFICATION.to_string(), schema: SIMPLE_SIG_SCHEMA.to_string(),
filename: sign_file_request.filename.clone(), filename: sign_file_request.filename.clone(),
digest: format!("{}-{}", HASH_ALGORITHM_SHA256, hex::encode(&sign_file_request.digest)), digest: format!("{}-{}", HASH_ALGORITHM_SHA256, hex::encode(&sign_file_request.digest)),
timestamp: sign_file_request.timestamp, timestamp: sign_file_request.timestamp,