|
4 | 4 |
|
5 | 5 | use anyhow::Context; |
6 | 6 | use base64::Engine; |
7 | | -use minisign::{sign, KeyPair as KP, SecretKey, SecretKeyBox, SignatureBox}; |
| 7 | +use minisign::{ |
| 8 | + sign, KeyPair as KP, PublicKey, PublicKeyBox, SecretKey, SecretKeyBox, SignatureBox, |
| 9 | +}; |
8 | 10 | use std::{ |
9 | 11 | fs::{self, File, OpenOptions}, |
10 | 12 | io::{BufReader, BufWriter, Write}, |
@@ -132,15 +134,24 @@ pub fn secret_key<S: AsRef<[u8]>>( |
132 | 134 | private_key: S, |
133 | 135 | password: Option<String>, |
134 | 136 | ) -> crate::Result<SecretKey> { |
135 | | - let decoded_secret = decode_key(private_key)?; |
136 | | - let sk_box = SecretKeyBox::from_string(&decoded_secret) |
137 | | - .with_context(|| "failed to load updater private key")?; |
| 137 | + let decoded_secret = decode_key(private_key).context("failed to decode base64 secret key")?; |
| 138 | + let sk_box = |
| 139 | + SecretKeyBox::from_string(&decoded_secret).context("failed to load updater private key")?; |
138 | 140 | let sk = sk_box |
139 | 141 | .into_secret_key(password) |
140 | | - .with_context(|| "incorrect updater private key password")?; |
| 142 | + .context("incorrect updater private key password")?; |
141 | 143 | Ok(sk) |
142 | 144 | } |
143 | 145 |
|
| 146 | +/// Gets the updater secret key from the given private key and password. |
| 147 | +pub fn pub_key<S: AsRef<[u8]>>(public_key: S) -> crate::Result<PublicKey> { |
| 148 | + let decoded_publick = decode_key(public_key).context("failed to decode base64 pubkey")?; |
| 149 | + let pk_box = |
| 150 | + PublicKeyBox::from_string(&decoded_publick).context("failed to load updater pubkey")?; |
| 151 | + let pk = pk_box.into_public_key()?; |
| 152 | + Ok(pk) |
| 153 | +} |
| 154 | + |
144 | 155 | fn unix_timestamp() -> u64 { |
145 | 156 | let start = SystemTime::now(); |
146 | 157 | let since_the_epoch = start |
|
0 commit comments