Skip to content

Commit b08a394

Browse files
authored
Move signature payload generation into signature scheme (#199)
1 parent 4c57bba commit b08a394

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/signature.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,7 @@ impl Bech32m<2, { Signature::LEN }> for Signature {
3232

3333
impl Display for Signature {
3434
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
35-
let (prefix, suffix) = self.scheme.prefix_and_suffix();
36-
37-
let payload = Bech32mPayload {
38-
prefix,
39-
data: self.inner.to_bytes(),
40-
suffix: suffix.into(),
41-
};
42-
43-
Self::encode_bech32m(f, payload)
35+
Self::encode_bech32m(f, self.scheme.payload(self.inner))
4436
}
4537
}
4638

src/signature_scheme.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,22 @@ impl SignatureScheme {
8888
}
8989
}
9090

91-
pub(crate) fn prefix_and_suffix(&self) -> ([Fe32; 2], &[u8]) {
91+
pub(crate) fn payload(
92+
&self,
93+
signature: ed25519_dalek::Signature,
94+
) -> Bech32mPayload<2, 64, Vec<u8>> {
9295
let prefix = self.discriminant().prefix();
9396

9497
let suffix = match self {
9598
SignatureScheme::Filepack | SignatureScheme::Ssh => &[],
9699
SignatureScheme::Pgp { hashed_area } => hashed_area.as_slice(),
97100
};
98101

99-
(prefix, suffix)
102+
Bech32mPayload {
103+
prefix,
104+
data: signature.to_bytes(),
105+
suffix: suffix.into(),
106+
}
100107
}
101108

102109
pub(crate) fn signed_data<'a>(&self, message: &'a SerializedMessage) -> Cow<'a, [u8]> {

0 commit comments

Comments
 (0)