[pbs-devel] [PATCH backup 2/4] bakckup::manifest: use tools::json for canonical representation
Wolfgang Bumiller
w.bumiller at proxmox.com
Fri Jan 15 10:20:47 CET 2021
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
src/backup/manifest.rs | 44 +-----------------------------------------
1 file changed, 1 insertion(+), 43 deletions(-)
diff --git a/src/backup/manifest.rs b/src/backup/manifest.rs
index 8742cb0a..d9a55655 100644
--- a/src/backup/manifest.rs
+++ b/src/backup/manifest.rs
@@ -149,49 +149,7 @@ impl BackupManifest {
// Generate canonical json
fn to_canonical_json(value: &Value) -> Result<Vec<u8>, Error> {
- let mut data = Vec::new();
- Self::write_canonical_json(value, &mut data)?;
- Ok(data)
- }
-
- 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() {
- Self::write_canonical_json(item, output)?;
- for item in iter {
- output.push(b',');
- Self::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();
- let mut iter = keys.into_iter();
- if let Some(key) = iter.next() {
- serde_json::to_writer(&mut *output, &key)?;
- output.push(b':');
- Self::write_canonical_json(&map[key], output)?;
- for key in iter {
- output.push(b',');
- serde_json::to_writer(&mut *output, &key)?;
- output.push(b':');
- Self::write_canonical_json(&map[key], output)?;
- }
- }
- output.push(b'}');
- }
- }
- Ok(())
+ crate::tools::json::to_canonical_json(value)
}
/// Compute manifest signature
--
2.20.1
More information about the pbs-devel
mailing list