Skip to content

Commit 7b8c63f

Browse files
committed
Added doctests to LogInfo and LogEntry merkle proof verification functions.
Signed-off-by: Victor Embacher <[email protected]>
1 parent 900423e commit 7b8c63f

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/rekor/models/consistency_proof.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl ConsistencyProof {
2828
ConsistencyProof { root_hash, hashes }
2929
}
3030

31+
/// Verify this consistency proof against the given parameters.
3132
pub fn verify(
3233
&self,
3334
old_size: usize,

src/rekor/models/log_entry.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,37 @@ pub struct Verification {
9191
}
9292

9393
impl LogEntry {
94+
/// Verifies that the log entry was included by a log in possession of `rekor_key`.
95+
///
96+
/// Example:
97+
/// ```rust
98+
/// use sigstore::rekor::apis::configuration::Configuration;
99+
/// use sigstore::rekor::apis::pubkey_api::get_public_key;
100+
/// use sigstore::rekor::apis::tlog_api::get_log_info;
101+
/// use sigstore::crypto::{CosignVerificationKey, SigningScheme};
102+
/// #[tokio::main]
103+
/// async fn main() {
104+
/// use sigstore::rekor::apis::entries_api::get_log_entry_by_index;
105+
/// let rekor_config = Configuration::default();
106+
/// // Important: in practice obtain the rekor key via TUF repo or another secure channel!
107+
/// let rekor_key = get_public_key(&rekor_config, None)
108+
/// .await
109+
/// .expect("failed to fetch pubkey from remote log");
110+
/// let rekor_key = CosignVerificationKey::from_pem(
111+
/// rekor_key.as_bytes(),
112+
/// &SigningScheme::ECDSA_P256_SHA256_ASN1,
113+
/// ).expect("failed to parse rekor key");
114+
///
115+
/// // fetch log info and then the most recent entry
116+
/// let log_info = get_log_info(&rekor_config)
117+
/// .await
118+
/// .expect("failed to fetch log info");
119+
/// let entry = get_log_entry_by_index(&rekor_config, (log_info.tree_size - 1) as i32)
120+
/// .await.expect("failed to fetch log entry");
121+
/// entry.verify_inclusion(&rekor_key)
122+
/// .expect("failed to verify inclusion");
123+
/// }
124+
/// ```
94125
pub fn verify_inclusion(&self, rekor_key: &CosignVerificationKey) -> Result<(), SigstoreError> {
95126
self.verification
96127
.inclusion_proof

src/rekor/models/log_info.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,49 @@ impl LogInfo {
4848
inactive_shards: None,
4949
}
5050
}
51-
51+
/// Verify the consistency of the proof provided by the log.
52+
///
53+
/// Example:
54+
/// ```rust
55+
/// use sigstore::crypto::{CosignVerificationKey, SigningScheme};
56+
/// use sigstore::rekor::apis::configuration::Configuration;
57+
/// use sigstore::rekor::apis::pubkey_api::get_public_key;
58+
/// use sigstore::rekor::apis::tlog_api::{get_log_info, get_log_proof};
59+
///
60+
/// #[tokio::main]
61+
/// async fn main() {
62+
/// let rekor_config = Configuration::default();
63+
///
64+
/// // Important: in practice obtain the rekor key via TUF repo or another secure channel!
65+
/// let rekor_key = get_public_key(&rekor_config, None)
66+
/// .await
67+
/// .expect("failed to fetch pubkey from remote log");
68+
/// let rekor_key = CosignVerificationKey::from_pem(
69+
/// rekor_key.as_bytes(),
70+
/// &SigningScheme::ECDSA_P256_SHA256_ASN1,
71+
/// ).expect("failed to parse rekor key");
72+
/// // fetch log info twice and run consistency proof
73+
/// let log_info1 = get_log_info(&rekor_config)
74+
/// .await
75+
/// .expect("failed to fetch data from remote");
76+
/// let log_info2 = get_log_info(&rekor_config)
77+
/// .await
78+
/// .expect("failed to fetch data from remote");
79+
///
80+
/// // get a proof using log_info1 as the previous tree state
81+
/// let proof = get_log_proof(
82+
/// &rekor_config,
83+
/// log_info2.tree_size as _,
84+
/// Some(&log_info1.tree_size.to_string()),
85+
/// None,
86+
/// )
87+
/// .await.expect("failed to fetch data from remote");
88+
/// log_info2
89+
/// .verify_consistency(log_info1.tree_size as usize, &log_info1.root_hash, &proof, &rekor_key)
90+
/// .expect("failed to verify log consistency");
91+
/// }
92+
///
93+
/// ```
5294
pub fn verify_consistency(
5395
&self,
5496
old_size: usize,

0 commit comments

Comments
 (0)