@@ -89,7 +89,7 @@ enum Command {
8989enum PlogCommand {
9090 /// Generate a new key
9191 #[structopt(name = "generate")]
92- Generate,
92+ Generate,
9393}
9494*/
9595
@@ -103,15 +103,14 @@ async fn main() -> Result<(), Error> {
103103 . quiet ( opt. quiet )
104104 . verbosity ( opt. verbosity )
105105 . init ( )
106- . map_err ( |e| bs_cli:: Error :: Log ( e ) ) ?;
106+ . map_err ( bs_cli:: Error :: Log ) ?;
107107
108108 // load the config
109- let mut config =
110- Config :: from_path ( opt. config , opt. keyfile , opt. sshagent , opt. sshagentenv ) ?;
109+ let config = Config :: from_path ( opt. config , opt. keyfile , opt. sshagent , opt. sshagentenv ) ?;
111110
112111 let ret = match opt. cmd {
113112 // process a config command
114- Command :: Config { cmd } => subcmds:: config:: go ( cmd, & mut config) . await ,
113+ Command :: Config { cmd } => subcmds:: config:: go ( cmd, & config) . await ,
115114 // process a plog command
116115 Command :: Plog { cmd } => subcmds:: plog:: go ( cmd, & config) . await ,
117116 } ;
@@ -128,183 +127,182 @@ async fn main() -> Result<(), Error> {
128127
129128 Ok ( ( ) )
130129}
131- /*
132- Command::Key { cmd } => {
133- match cmd {
134- /*
135- KeyCommand::Default { clear, hash } => {
136- let mut config =
137- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
138-
139- if clear {
140- config.set_default_key(None)?;
141- } else if let Some(hash) = hash {
142- config.set_default_key(Some(hash))?;
143- }
144-
145- if let Ok(key) = config.default_key() {
146- let kh = {
147- let fv = key.fingerprint_view()?;
148- EncodedMultihash::new(Base::Base58Btc, fv.fingerprint(Codec::Blake2S256)?)
149- };
150- println!("{} {} {}", key.codec(), kh, key.comment,);
151- } else {
152- println!("No default key set");
153- }
130+ /*
131+ Command::Key { cmd } => {
132+ match cmd {
133+ /*
134+ KeyCommand::Default { clear, hash } => {
135+ let mut config =
136+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
137+
138+ if clear {
139+ config.set_default_key(None)?;
140+ } else if let Some(hash) = hash {
141+ config.set_default_key(Some(hash))?;
154142 }
155- */
156- KeyCommand::Generate { key_type, comment, threshold, limit } => {
157- // get the key codec
158- let codec = match key_type {
159- Some(kt) => {
160- Some(match kt.to_lowercase().as_str() {
161- "eddsa" => Codec::Ed25519Priv,
162- "es256k" => Codec::Secp256K1Priv,
163- "blsg1" => Codec::Bls12381G1Priv,
164- "blsg2" => Codec::Bls12381G2Priv,
165- _ => return Err(Error::InvalidKeyType(kt)),
166- })
167- }
168- None => None
143+
144+ if let Ok(key) = config.default_key() {
145+ let kh = {
146+ let fv = key.fingerprint_view()?;
147+ EncodedMultihash::new(Base::Base58Btc, fv.fingerprint(Codec::Blake2S256)?)
169148 };
149+ println!("{} {} {}", key.codec(), kh, key.comment,);
150+ } else {
151+ println!("No default key set");
152+ }
153+ }
154+ */
155+ KeyCommand::Generate { key_type, comment, threshold, limit } => {
156+ // get the key codec
157+ let codec = match key_type {
158+ Some(kt) => {
159+ Some(match kt.to_lowercase().as_str() {
160+ "eddsa" => Codec::Ed25519Priv,
161+ "es256k" => Codec::Secp256K1Priv,
162+ "blsg1" => Codec::Bls12381G1Priv,
163+ "blsg2" => Codec::Bls12381G2Priv,
164+ _ => return Err(Error::InvalidKeyType(kt)),
165+ })
166+ }
167+ None => None
168+ };
170169
171- // generate the new key
172- let gk = key::gen("a new key", codec, comment, (threshold, limit)).await?;
170+ // generate the new key
171+ let gk = key::gen("a new key", codec, comment, (threshold, limit)).await?;
173172
174- // get the config
175- let mut config =
176- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
173+ // get the config
174+ let mut config =
175+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
177176
178- // add the key to the keychain
179- config.keychain()?.borrow_mut().add(&gk)?;
180- }
181- KeyCommand::List => {
182- // load the config
183- let mut config =
184- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
185- let keys = config.keychain()?.borrow().list()?;
186- for key in &keys {
187- println!("{}", key);
188- }
177+ // add the key to the keychain
178+ config.keychain()?.borrow_mut().add(&gk)?;
179+ }
180+ KeyCommand::List => {
181+ // load the config
182+ let mut config =
183+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
184+ let keys = config.keychain()?.borrow().list()?;
185+ for key in &keys {
186+ println!("{}", key);
189187 }
190- /*
191- Command::Sign {
192- keyhash,
193- encoding,
194- combined,
195- signature,
196- msg,
197- } => {
198- // load the config
199- let mut config =
200- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
201-
202- // look up the signing key by hash
203- let keyhash = match keyhash {
204- Some(h) => EncodedMultihash::try_from(h.as_str())?,
205- None => config.default_key_fingerprint()?,
206- };
207- debug!("keyhash: {:?}", keyhash);
208- let encoding = encoding.unwrap_or("identity".to_string());
209- let encoding = Codec::try_from(encoding.as_str())?;
210- let key = config.keychain()?.borrow().get(&keyhash)?;
211- let emk: EncodedMultikey = key.clone().into();
212- debug!("signing key: {:?}", emk);
213-
214- // read the msg from either the file or stdin
188+ }
189+ /*
190+ Command::Sign {
191+ keyhash,
192+ encoding,
193+ combined,
194+ signature,
195+ msg,
196+ } => {
197+ // load the config
198+ let mut config =
199+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
200+
201+ // look up the signing key by hash
202+ let keyhash = match keyhash {
203+ Some(h) => EncodedMultihash::try_from(h.as_str())?,
204+ None => config.default_key_fingerprint()?,
205+ };
206+ debug!("keyhash: {:?}", keyhash);
207+ let encoding = encoding.unwrap_or("identity".to_string());
208+ let encoding = Codec::try_from(encoding.as_str())?;
209+ let key = config.keychain()?.borrow().get(&keyhash)?;
210+ let emk: EncodedMultikey = key.clone().into();
211+ debug!("signing key: {:?}", emk);
212+
213+ // read the msg from either the file or stdin
214+ let mut r = reader(&msg)?;
215+ let mut m = Vec::default();
216+ r.read_to_end(&mut m)?;
217+
218+ // determine if this is a combined signature
219+ let combined = combined.unwrap_or_default();
220+
221+ // generate multisig
222+ let ms = config
223+ .keychain()?
224+ .borrow_mut()
225+ .sign(&key, combined, encoding, &m)?;
226+ let ems: EncodedMultisig = ms.clone().into();
227+ debug!("signature: {:?}", ems);
228+ let out: Vec<u8> = ms.into();
229+
230+ let mut w = writer(&signature)?;
231+ w.write_all(&out)?;
232+ println!("signed!");
233+ }
234+ */
235+ /*
236+ Command::Verify {
237+ keyhash,
238+ signature,
239+ msg,
240+ } => {
241+ // load the config
242+ let mut config =
243+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
244+
245+ // look up the signing key by hash
246+ let keyhash = match keyhash {
247+ Some(h) => EncodedMultihash::try_from(h.as_str())?,
248+ None => config.default_key_fingerprint()?,
249+ };
250+ debug!("keyhash: {:?}", keyhash);
251+ let key = config.keychain()?.borrow().get(&keyhash)?;
252+ let emk: EncodedMultikey = key.clone().into();
253+ debug!("verifying key: {:?}", emk);
254+
255+ // read the signature data from file
256+ let ms = {
257+ let mut r = File::open(&signature)?;
258+ let mut s = Vec::default();
259+ r.read_to_end(&mut s)?;
260+ Multisig::try_from(s.as_slice())?
261+ };
262+ let ems: EncodedMultisig = ms.clone().into();
263+ debug!("signature: {:?}", ems);
264+
265+ // get the message
266+ let m = if ms.message.is_empty() {
267+ // read the msg from either the file of stdin
215268 let mut r = reader(&msg)?;
216269 let mut m = Vec::default();
217270 r.read_to_end(&mut m)?;
218-
219- // determine if this is a combined signature
220- let combined = combined.unwrap_or_default();
221-
222- // generate multisig
223- let ms = config
224- .keychain()?
225- .borrow_mut()
226- .sign(&key, combined, encoding, &m)?;
227- let ems: EncodedMultisig = ms.clone().into();
228- debug!("signature: {:?}", ems);
229- let out: Vec<u8> = ms.into();
230-
231- let mut w = writer(&signature)?;
232- w.write_all(&out)?;
233- println!("signed!");
234- }
235- */
236- /*
237- Command::Verify {
238- keyhash,
239- signature,
240- msg,
241- } => {
242- // load the config
243- let mut config =
244- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
245-
246- // look up the signing key by hash
247- let keyhash = match keyhash {
248- Some(h) => EncodedMultihash::try_from(h.as_str())?,
249- None => config.default_key_fingerprint()?,
250- };
251- debug!("keyhash: {:?}", keyhash);
252- let key = config.keychain()?.borrow().get(&keyhash)?;
253- let emk: EncodedMultikey = key.clone().into();
254- debug!("verifying key: {:?}", emk);
255-
256- // read the signature data from file
257- let ms = {
258- let mut r = File::open(&signature)?;
259- let mut s = Vec::default();
260- r.read_to_end(&mut s)?;
261- Multisig::try_from(s.as_slice())?
262- };
263- let ems: EncodedMultisig = ms.clone().into();
264- debug!("signature: {:?}", ems);
265-
266- // get the message
267- let m = if ms.message.is_empty() {
268- // read the msg from either the file of stdin
269- let mut r = reader(&msg)?;
270- let mut m = Vec::default();
271- r.read_to_end(&mut m)?;
272- m
273- } else {
274- ms.message.clone()
275- };
276-
277- // verify multisig
278- let vv = key.verify_view()?;
279- vv.verify(&ms, Some(m.as_slice()))?;
280- println!("signature valid!");
281- }
282- */
283- /*
284- Command::Remove { name } => {
285- let mut config =
286- Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
287- let mut keychain = config.keychain()?;
288- let key = config.default_key()?;
289- if key.comment().to_string() == name {
290- config.set_default_key(None)?;
291- keychain.
292- }
271+ m
272+ } else {
273+ ms.message.clone()
274+ };
275+
276+ // verify multisig
277+ let vv = key.verify_view()?;
278+ vv.verify(&ms, Some(m.as_slice()))?;
279+ println!("signature valid!");
280+ }
281+ */
282+ /*
283+ Command::Remove { name } => {
284+ let mut config =
285+ Config::from_path(opt.config, opt.keyfile, opt.sshagent, opt.sshagentenv)?;
286+ let mut keychain = config.keychain()?;
287+ let key = config.default_key()?;
288+ if key.comment().to_string() == name {
289+ config.set_default_key(None)?;
290+ keychain.
293291 }
294- */
295292 }
293+ */
296294 }
297- /*
298- Command::Plog { cmd } => {
299- match cmd {
300- PlogCommand::Generate => {
301- // generate the new key
302- let plog = plog::gen("for fun").await?;
303- println!("{:?}", plog) ;
304- }
295+ }
296+ /*
297+ Command::Plog { cmd } => {
298+ match cmd {
299+ PlogCommand::Generate => {
300+ // generate the new key
301+ let plog = plog::gen("for fun").await? ;
302+ println!("{:?}", plog);
305303 }
306304 }
307- */
308305 }
309306 */
310-
307+ }
308+ */
0 commit comments