mirror of
git://git.proxmox.com/git/proxmox-backup.git
synced 2025-01-05 09:17:59 +03:00
move to/write_canonical_json to proxmox-serde
as preparation for extracting subscription-related code into its own crate. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
8e76134db9
commit
87b7fa0226
@ -103,7 +103,7 @@ proxmox-section-config = "1"
|
||||
proxmox-tfa = { version = "2", features = [ "api", "api-types" ] }
|
||||
proxmox-time = "1.1.2"
|
||||
proxmox-uuid = "1"
|
||||
proxmox-serde = "0.1"
|
||||
proxmox-serde = { version = "0.1.1", features = [ "serde_json" ] }
|
||||
proxmox-shared-memory = "0.2"
|
||||
proxmox-sys = { version = "0.3.1", features = [ "sortable-macro" ] }
|
||||
proxmox-compression = "0.1"
|
||||
|
3
debian/control
vendored
3
debian/control
vendored
@ -62,7 +62,8 @@ Build-Depends: debhelper (>= 12),
|
||||
librust-proxmox-schema-1+default-dev (>= 1.3.1-~~),
|
||||
librust-proxmox-schema-1+upid-api-impl-dev (>= 1.3.1-~~),
|
||||
librust-proxmox-section-config-1+default-dev,
|
||||
librust-proxmox-serde-0.1+default-dev,
|
||||
librust-proxmox-serde-0.1+default-dev (>= 0.1.1~~),
|
||||
librust-proxmox-serde-0.1+serde-json-dev (>= 0.1.1~~),
|
||||
librust-proxmox-shared-memory-0.2+default-dev,
|
||||
librust-proxmox-sys-0.3+default-dev (>= 0.3.1-~~),
|
||||
librust-proxmox-sys-0.3+logrotate-dev (>= 0.3.1-~~),
|
||||
|
@ -30,6 +30,7 @@ proxmox-borrow = "1"
|
||||
proxmox-io = "1"
|
||||
proxmox-lang = "1.1"
|
||||
proxmox-schema = { version = "1.3.1", features = [ "api-macro" ] }
|
||||
proxmox-serde = { version = "0.1.1", features = [ "serde_json" ] }
|
||||
proxmox-time = "1"
|
||||
proxmox-uuid = "1"
|
||||
proxmox-sys = "0.3.1"
|
||||
|
@ -140,7 +140,7 @@ impl BackupManifest {
|
||||
|
||||
// Generate canonical json
|
||||
fn to_canonical_json(value: &Value) -> Result<Vec<u8>, Error> {
|
||||
pbs_tools::json::to_canonical_json(value)
|
||||
proxmox_serde::json::to_canonical_json(value)
|
||||
}
|
||||
|
||||
/// Compute manifest signature
|
||||
|
@ -1,53 +1,5 @@
|
||||
use anyhow::{bail, format_err, Error};
|
||||
use serde_json::Value;
|
||||
|
||||
// Generate canonical json
|
||||
pub fn to_canonical_json(value: &Value) -> Result<Vec<u8>, Error> {
|
||||
let mut data = Vec::new();
|
||||
write_canonical_json(value, &mut data)?;
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
pub fn write_canonical_json(value: &Value, output: &mut Vec<u8>) -> Result<(), Error> {
|
||||
match value {
|
||||
Value::Null => bail!("got unexpected null value"),
|
||||
Value::String(_) | Value::Number(_) | Value::Bool(_) => {
|
||||
serde_json::to_writer(output, &value)?;
|
||||
}
|
||||
Value::Array(list) => {
|
||||
output.push(b'[');
|
||||
let mut iter = list.iter();
|
||||
if let Some(item) = iter.next() {
|
||||
write_canonical_json(item, output)?;
|
||||
for item in iter {
|
||||
output.push(b',');
|
||||
write_canonical_json(item, output)?;
|
||||
}
|
||||
}
|
||||
output.push(b']');
|
||||
}
|
||||
Value::Object(map) => {
|
||||
output.push(b'{');
|
||||
let mut keys: Vec<&str> = map.keys().map(String::as_str).collect();
|
||||
keys.sort_unstable();
|
||||
let mut iter = keys.into_iter();
|
||||
if let Some(key) = iter.next() {
|
||||
serde_json::to_writer(&mut *output, &key)?;
|
||||
output.push(b':');
|
||||
write_canonical_json(&map[key], output)?;
|
||||
for key in iter {
|
||||
output.push(b',');
|
||||
serde_json::to_writer(&mut *output, &key)?;
|
||||
output.push(b':');
|
||||
write_canonical_json(&map[key], output)?;
|
||||
}
|
||||
}
|
||||
output.push(b'}');
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn json_object_to_query(data: Value) -> Result<String, Error> {
|
||||
let mut query = url::form_urlencoded::Serializer::new(String::new());
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub fn read() -> Result<TfaConfig, Error> {
|
||||
}
|
||||
|
||||
pub(crate) fn webauthn_config_digest(config: &WebauthnConfig) -> Result<[u8; 32], Error> {
|
||||
let digest_data = pbs_tools::json::to_canonical_json(&serde_json::to_value(config)?)?;
|
||||
let digest_data = proxmox_serde::json::to_canonical_json(&serde_json::to_value(config)?)?;
|
||||
Ok(openssl::sha::sha256(&digest_data))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user