Skip to content

Commit ef2d094

Browse files
committed
add versions check
1 parent 3cf40f1 commit ef2d094

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! 'copyright' field defition
2+
3+
#[derive(serde::Deserialize)]
4+
pub struct Copyright {
5+
pub versions: Vec<Version>,
6+
}
7+
8+
#[derive(serde::Deserialize)]
9+
pub struct Version {
10+
pub version: String,
11+
}

rust/catalyst-signed-doc-spec/src/lib.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
33
#![allow(missing_docs, clippy::missing_docs_in_private_items)]
44

5+
pub mod copyright;
56
pub mod doc_types;
67
pub mod headers;
78
pub mod is_required;
89
pub mod metadata;
910

1011
use std::collections::HashMap;
1112

12-
use build_info;
13+
use build_info as build_info_lib;
1314

14-
use crate::{headers::Headers, metadata::Metadata};
15+
use crate::{copyright::Copyright, headers::Headers, metadata::Metadata};
1516

16-
build_info::build_info!(pub(crate) fn build_info);
17+
build_info_lib::build_info!(pub(crate) fn build_info);
1718

1819
/// Catalyst Signed Document spec representation struct
1920
#[derive(serde::Deserialize)]
2021
pub struct CatalystSignedDocSpec {
21-
/// A collection of document's specs
2222
pub docs: HashMap<DocumentName, DocSpec>,
23+
pub copyright: Copyright,
2324
}
2425

2526
// A thin wrapper over the string document name values
@@ -58,11 +59,20 @@ pub struct DocSpec {
5859
impl CatalystSignedDocSpec {
5960
/// Loading a Catalyst Signed Documents spec from the `signed_doc.json`
6061
pub fn load_signed_doc_spec() -> anyhow::Result<CatalystSignedDocSpec> {
61-
let crate_version = build_info().crate_info.version.to_string();
62-
6362
let signed_doc_str = include_str!("../../../specs/signed_doc.json");
64-
let signed_doc_spec = serde_json::from_str(signed_doc_str)
63+
let signed_doc_spec: CatalystSignedDocSpec = serde_json::from_str(signed_doc_str)
6564
.map_err(|e| anyhow::anyhow!("Invalid Catalyst Signed Documents JSON Spec: {e}"))?;
65+
66+
let crate_version = build_info().crate_info.version.to_string();
67+
let latest_version = signed_doc_spec
68+
.copyright
69+
.versions
70+
.last()
71+
.ok_or(anyhow::anyhow!(
72+
"'versions' list must have at least one entry"
73+
))?;
74+
anyhow::ensure!(latest_version.version == crate_version, "crate version should align with the latest version of the Catalyst Signed Documents specification");
75+
6676
Ok(signed_doc_spec)
6777
}
6878
}

0 commit comments

Comments
 (0)