|
2 | 2 |
|
3 | 3 | #![allow(missing_docs, clippy::missing_docs_in_private_items)] |
4 | 4 |
|
| 5 | +pub mod copyright; |
5 | 6 | pub mod doc_types; |
6 | 7 | pub mod headers; |
7 | 8 | pub mod is_required; |
8 | 9 | pub mod metadata; |
9 | 10 |
|
10 | 11 | use std::collections::HashMap; |
11 | 12 |
|
12 | | -use build_info; |
| 13 | +use build_info as build_info_lib; |
13 | 14 |
|
14 | | -use crate::{headers::Headers, metadata::Metadata}; |
| 15 | +use crate::{copyright::Copyright, headers::Headers, metadata::Metadata}; |
15 | 16 |
|
16 | | -build_info::build_info!(pub(crate) fn build_info); |
| 17 | +build_info_lib::build_info!(pub(crate) fn build_info); |
17 | 18 |
|
18 | 19 | /// Catalyst Signed Document spec representation struct |
19 | 20 | #[derive(serde::Deserialize)] |
20 | 21 | pub struct CatalystSignedDocSpec { |
21 | | - /// A collection of document's specs |
22 | 22 | pub docs: HashMap<DocumentName, DocSpec>, |
| 23 | + pub copyright: Copyright, |
23 | 24 | } |
24 | 25 |
|
25 | 26 | // A thin wrapper over the string document name values |
@@ -58,11 +59,20 @@ pub struct DocSpec { |
58 | 59 | impl CatalystSignedDocSpec { |
59 | 60 | /// Loading a Catalyst Signed Documents spec from the `signed_doc.json` |
60 | 61 | pub fn load_signed_doc_spec() -> anyhow::Result<CatalystSignedDocSpec> { |
61 | | - let crate_version = build_info().crate_info.version.to_string(); |
62 | | - |
63 | 62 | 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) |
65 | 64 | .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 | + |
66 | 76 | Ok(signed_doc_spec) |
67 | 77 | } |
68 | 78 | } |
|
0 commit comments