summaryrefslogtreecommitdiffstats
path: root/guide/src/chapter_01.md
diff options
context:
space:
mode:
Diffstat (limited to 'guide/src/chapter_01.md')
-rw-r--r--guide/src/chapter_01.md204
1 files changed, 124 insertions, 80 deletions
diff --git a/guide/src/chapter_01.md b/guide/src/chapter_01.md
index f5663bc9..8d973e07 100644
--- a/guide/src/chapter_01.md
+++ b/guide/src/chapter_01.md
@@ -101,30 +101,41 @@ fn main() {
# Ok(vec![self.tpk.clone()])
# }
#
-# fn check(&mut self, sigs: Vec<Vec<VerificationResult>>)
+# fn check(&mut self, structure: &MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
#
-# // First, we are interested in signatures over the data,
-# // i.e. level 0 signatures.
-# let sigs_over_data = sigs.get(0)
-# .ok_or_else(|| failure::err_msg("No level 0 signatures found"))?;
-#
-# // Now, let's see if there is a signature on that level.
-# let sig_result = sigs_over_data.get(0)
-# .ok_or_else(|| failure::err_msg("No signature found"))?;
-#
-# // Finally, given a VerificationResult, which only says
-# // whether the signature checks out mathematically, we apply
-# // our policy.
-# match sig_result {
-# VerificationResult::GoodChecksum(..) =>
-# Ok(()), // Good signature
-# VerificationResult::MissingKey(_) =>
-# Err(failure::err_msg("Missing key to verify signature")),
-# VerificationResult::BadChecksum(_) =>
-# Err(failure::err_msg("Bad signature")),
+# let mut good = false;
+# for (i, layer) in structure.iter().enumerate() {
+# match (i, layer) {
+# // First, we are interested in signatures over the
+# // data, i.e. level 0 signatures.
+# (0, MessageLayer::SignatureGroup { ref results }) => {
+# // Finally, given a VerificationResult, which only says
+# // whether the signature checks out mathematically, we apply
+# // our policy.
+# match results.get(0) {
+# Some(VerificationResult::GoodChecksum(..)) =>
+# good = true,
+# Some(VerificationResult::MissingKey(_)) =>
+# return Err(failure::err_msg(
+# "Missing key to verify signature")),
+# Some(VerificationResult::BadChecksum(_)) =>
+# return Err(failure::err_msg("Bad signature")),
+# None =>
+# return Err(failure::err_msg("No signature")),
+# }
+# },
+# _ => return Err(failure::err_msg(
+# "Unexpected message structure")),
+# }
+# }
+#
+# if good {
+# Ok(()) // Good signature.
+# } else {
+# Err(failure::err_msg("Signature verification failed"))
# }
# }
# }
@@ -231,30 +242,41 @@ fn generate() -> openpgp::Result<openpgp::TPK> {
# Ok(vec![self.tpk.clone()])
# }
#
-# fn check(&mut self, sigs: Vec<Vec<VerificationResult>>)
+# fn check(&mut self, structure: &MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
#
-# // First, we are interested in signatures over the data,
-# // i.e. level 0 signatures.
-# let sigs_over_data = sigs.get(0)
-# .ok_or_else(|| failure::err_msg("No level 0 signatures found"))?;
-#
-# // Now, let's see if there is a signature on that level.
-# let sig_result = sigs_over_data.get(0)
-# .ok_or_else(|| failure::err_msg("No signature found"))?;
-#
-# // Finally, given a VerificationResult, which only says
-# // whether the signature checks out mathematically, we apply
-# // our policy.
-# match sig_result {
-# VerificationResult::GoodChecksum(..) =>
-# Ok(()), // Good signature
-# VerificationResult::MissingKey(_) =>
-# Err(failure::err_msg("Missing key to verify signature")),
-# VerificationResult::BadChecksum(_) =>
-# Err(failure::err_msg("Bad signature")),
+# let mut good = false;
+# for (i, layer) in structure.iter().enumerate() {
+# match (i, layer) {
+# // First, we are interested in signatures over the
+# // data, i.e. level 0 signatures.
+# (0, MessageLayer::SignatureGroup { ref results }) => {
+# // Finally, given a VerificationResult, which only says
+# // whether the signature checks out mathematically, we apply
+# // our policy.
+# match results.get(0) {
+# Some(VerificationResult::GoodChecksum(..)) =>
+# good = true,
+# Some(VerificationResult::MissingKey(_)) =>
+# return Err(failure::err_msg(
+# "Missing key to verify signature")),
+# Some(VerificationResult::BadChecksum(_)) =>
+# return Err(failure::err_msg("Bad signature")),
+# None =>
+# return Err(failure::err_msg("No signature")),
+# }
+# },
+# _ => return Err(failure::err_msg(
+# "Unexpected message structure")),
+# }
+# }
+#
+# if good {
+# Ok(()) // Good signature.
+# } else {
+# Err(failure::err_msg("Signature verification failed"))
# }
# }
# }
@@ -361,30 +383,41 @@ fn sign(sink: &mut Write, plaintext: &str, tsk: &openpgp::TPK)
# Ok(vec![self.tpk.clone()])
# }
#
-# fn check(&mut self, sigs: Vec<Vec<VerificationResult>>)
+# fn check(&mut self, structure: &MessageStructure)
# -> openpgp::Result<()> {
# // In this function, we implement our signature verification
# // policy.
#
-# // First, we are interested in signatures over the data,
-# // i.e. level 0 signatures.
-# let sigs_over_data = sigs.get(0)
-# .ok_or_else(|| failure::err_msg("No level 0 signatures found"))?;
-#
-# // Now, let's see if there is a signature on that level.
-# let sig_result = sigs_over_data.get(0)
-# .ok_or_else(|| failure::err_msg("No signature found"))?;
-#
-# // Finally, given a VerificationResult, which only says
-# // whether the signature checks out mathematically, we apply
-# // our policy.
-# match sig_result {
-# VerificationResult::GoodChecksum(..) =>
-# Ok(()), // Good signature
-# VerificationResult::MissingKey(_) =>
-# Err(failure::err_msg("Missing key to verify signature")),
-# VerificationResult::BadChecksum(_) =>
-# Err(failure::err_msg("Bad signature")),
+# let mut good = false;
+# for (i, layer) in structure.iter().enumerate() {
+# match (i, layer) {
+# // First, we are interested in signatures over the
+# // data, i.e. level 0 signatures.
+# (0, MessageLayer::SignatureGroup { ref results }) => {
+# // Finally, given a VerificationResult, which only says
+# // whether the signature checks out mathematically, we apply
+# // our policy.
+# match results.get(0) {
+# Some(VerificationResult::GoodChecksum(..)) =>
+# good = true,
+# Some(VerificationResult::MissingKey(_)) =>
+# return Err(failure::err_msg(
+# "Missing key to verify signature")),
+# Some(VerificationResult::BadChecksum(_)) =>
+# return Err(failure::err_msg("Bad signature")),
+# None =>
+# return Err(failure::err_msg("No signature")),
+# }
+# },
+# _ => return Err(failure::err_msg(
+# "Unexpected message structure")),
+# }
+# }
+#
+# if good {
+# Ok(()) // Good signature.
+# } else {
+# Err(failure::err_msg("Signature verification failed"))
# }
# }
# }
@@ -502,30 +535,41 @@ impl<'a> VerificationHelper for Helper<'a> {
Ok(vec![self.tpk.clone()])
}
- fn check(&mut self, sigs: Vec<Vec<VerificationResult>>)
+ fn check(&mut self, structure: &MessageStructure)
-> openpgp::Result<()> {
// In this function, we implement our signature verification
// policy.
- // First, we are interested in signatures over the data,
- // i.e. level 0 signatures.
- let sigs_over_data = sigs.get(0)
- .ok_or_else(|| failure::err_msg("No level 0 signatures found"))?;
-
- // Now, let's see if there is a signature on that level.
- let sig_result = sigs_over_data.get(0)
- .ok_or_else(|| failure::err_msg("No signature found"))?;
-
- // Finally, given a VerificationResult, which only says
- // whether the signature checks out mathematically, we apply
- // our policy.
- match sig_result {
- VerificationResult::GoodChecksum(..) =>
- Ok(()), // Good signature
- VerificationResult::MissingKey(_) =>
- Err(failure::err_msg("Missing key to verify signature")),
- VerificationResult::BadChecksum(_) =>
- Err(failure::err_msg("Bad signature")),
+ let mut good = false;
+ for (i, layer) in structure.iter().enumerate() {
+ match (i, layer) {
+ // First, we are interested in signatures over the
+ // data, i.e. level 0 signatures.
+ (0, MessageLayer::SignatureGroup { ref results }) => {
+ // Finally, given a VerificationResult, which only says
+ // whether the signature checks out mathematically, we apply
+ // our policy.
+ match results.get(0) {
+ Some(VerificationResult::GoodChecksum(..)) =>
+ good = true,
+ Some(VerificationResult::MissingKey(_)) =>
+ return Err(failure::err_msg(
+ "Missing key to verify signature")),
+ Some(VerificationResult::BadChecksum(_)) =>
+ return Err(failure::err_msg("Bad signature")),
+ None =>
+ return Err(failure::err_msg("No signature")),
+ }
+ },
+ _ => return Err(failure::err_msg(
+ "Unexpected message structure")),
+ }
+ }
+
+ if good {
+ Ok(()) // Good signature.
+ } else {
+ Err(failure::err_msg("Signature verification failed"))
}
}
}