From 57782c4ce5c60819e42479c77f3fa342eb688046 Mon Sep 17 00:00:00 2001 From: kazuki0824 Date: Tue, 19 Jul 2022 02:15:37 +0900 Subject: [PATCH] Reformat code --- b25-sys/src/access_control.rs | 27 ++++-- b25-sys/src/access_control/block00_mac.rs | 22 ++--- .../src/access_control/block00_structure.rs | 12 +-- b25-sys/src/bindings/arib_std_b25.rs | 91 +++++++++---------- b25-sys/src/bindings/ffi.rs | 7 +- b25-sys/src/bindings/mod.rs | 8 +- b25-sys/src/lib.rs | 4 +- recisdb-rs/src/context.rs | 4 +- recisdb-rs/src/main.rs | 25 +++-- recisdb-rs/src/tuner_base.rs | 10 +- recisdb-rs/src/tuner_base/linux.rs | 18 ++-- recisdb-rs/src/tuner_base/windows.rs | 8 +- recisdb-rs/src/utils.rs | 32 +++---- 13 files changed, 138 insertions(+), 130 deletions(-) diff --git a/b25-sys/src/access_control.rs b/b25-sys/src/access_control.rs index adc5c23..d5b75a2 100644 --- a/b25-sys/src/access_control.rs +++ b/b25-sys/src/access_control.rs @@ -1,14 +1,15 @@ +use crate::access_control::block00_mac::verify_mac; +use crate::access_control::block00_structure::{expand_00, Block00}; +use crate::access_control::types::Block00CbcDec; use std::ops::Deref; use tail_cbc::cipher::{Key, KeyIvInit}; use tail_cbc::UnalignedBytesDecryptMut; -use crate::access_control::block00_mac::verify_mac; -use crate::access_control::block00_structure::{Block00, expand_00}; -use crate::access_control::types::Block00CbcDec; -pub mod types; +mod block00_mac; mod block00_structure; +mod block40_structure; mod macros; -mod block00_mac; +pub mod types; pub(crate) fn select_key_by_auth(payload: &mut [u8]) -> Option> { let size = payload.len(); @@ -20,22 +21,28 @@ pub(crate) fn select_key_by_auth(payload: &mut [u8]) -> Option> { let encrypted_part = &mut payload[3..]; let mut ret = None; - for k in if working_key_id % 2 == 1 { crate::KEY1.lock() } else { crate::KEY0.lock() }.unwrap().deref() + for k in if working_key_id % 2 == 1 { + crate::KEY1.lock() + } else { + crate::KEY0.lock() + } + .unwrap() + .deref() { let expanded_key = expand_00(*k, 0); let mut dec = Block00CbcDec::new(&expanded_key, &0xfe27199919690911u64.to_be_bytes().into()); - dec.decrypt_bytes_b2b_mut(encrypted_part, &mut temp[3..]).expect("decryption failed"); + dec.decrypt_bytes_b2b_mut(encrypted_part, &mut temp[3..]) + .expect("decryption failed"); //mac is the last 4 bytes of the payload let (content, mac) = temp.split_at_mut(size - 4); - if verify_mac(mac, content, k.to_le_bytes().into()).is_ok() - { + if verify_mac(mac, content, k.to_le_bytes().into()).is_ok() { encrypted_part.copy_from_slice(&temp[3..]); ret = Some(expanded_key); break; } } ret -} \ No newline at end of file +} diff --git a/b25-sys/src/access_control/block00_mac.rs b/b25-sys/src/access_control/block00_mac.rs index 8002bca..367253d 100644 --- a/b25-sys/src/access_control/block00_mac.rs +++ b/b25-sys/src/access_control/block00_mac.rs @@ -1,18 +1,17 @@ -use cbc_mac::{CbcMac, Mac}; +use crate::access_control::block00_structure::BlockSize00; use cbc_mac::digest::MacError; +use cbc_mac::{CbcMac, Mac}; use cryptography_00::feistel; use tail_cbc::cipher; -use tail_cbc::cipher::{BlockCipher, InvalidLength, Key, KeyInit, KeySizeUser}; use tail_cbc::cipher::typenum::{U1, U8}; -use crate::access_control::block00_structure::BlockSize00; +use tail_cbc::cipher::{BlockCipher, InvalidLength, Key, KeyInit, KeySizeUser}; type KeySizeRound = U8; -pub fn verify_mac(mac: &[u8], text: &[u8], key: Key) -> Result<(), MacError> -{ +pub fn verify_mac(mac: &[u8], text: &[u8], key: Key) -> Result<(), MacError> { let mut cbc_mac = as Mac>::new(&key); cbc_mac.update(text); - cbc_mac.verify_truncated_right(mac.into()) + cbc_mac.verify_truncated_right(mac) } #[derive(Clone)] @@ -32,7 +31,7 @@ impl KeyInit for Round00 { 8 => { let key = u64::from_le_bytes(key.try_into().unwrap()); Ok(Self { key }) - }, + } _ => Err(InvalidLength), } } @@ -72,9 +71,10 @@ fn test_verify_cbcmac_zero() { #[test] fn test_verify_cbcmac_unaligned_random_values() { let key = 0x0001020304050607u64.to_le_bytes(); - let ciphertext = [ 0xC6, 0x80, 0x20, 0x3A, 0x53, 0x1E, 0x5C, 0xC7, - 0xB6, 0x08, 0xAF, 0xA1, 0x2B, 0x19, 0x26, 0x8A, - 0x47, 0xE1, 0x86, 0x74, 0xE9, ]; + let ciphertext = [ + 0xC6, 0x80, 0x20, 0x3A, 0x53, 0x1E, 0x5C, 0xC7, 0xB6, 0x08, 0xAF, 0xA1, 0x2B, 0x19, 0x26, + 0x8A, 0x47, 0xE1, 0x86, 0x74, 0xE9, + ]; let mac = (0x6e4087f4ef22b5du64).to_be_bytes(); assert!(verify_mac(&mac, &ciphertext, key.into()).is_ok()); -} \ No newline at end of file +} diff --git a/b25-sys/src/access_control/block00_structure.rs b/b25-sys/src/access_control/block00_structure.rs index 863562e..d4b8d44 100644 --- a/b25-sys/src/access_control/block00_structure.rs +++ b/b25-sys/src/access_control/block00_structure.rs @@ -1,7 +1,7 @@ use cryptography_00::{feistel, round_function}; use tail_cbc::cipher; -use tail_cbc::cipher::{BlockCipher, InvalidLength, Key, KeyInit, KeySizeUser}; use tail_cbc::cipher::typenum::{U16, U3, U8}; +use tail_cbc::cipher::{BlockCipher, InvalidLength, Key, KeyInit, KeySizeUser}; type KeySize00 = U16; pub(crate) type BlockSize00 = U8; @@ -25,9 +25,9 @@ pub(crate) fn expand_00(key: u64, protocol: u8) -> Key { } Key::::from_exact_iter( //no vec - exp00.into_iter().map(|x| x.to_le_bytes()).flatten(), + exp00.into_iter().flat_map(|x| x.to_le_bytes()), ) - .unwrap() + .unwrap() } #[derive(Clone)] @@ -100,7 +100,6 @@ crate::impl_block_encdec!( ); const ROUND_INDEX: [u8; 16] = [1, 0, 1, 2, 2, 2, 0, 2, 1, 3, 0, 2, 1, 0, 0, 1]; - #[test] fn cbc() { use cipher::KeyIvInit; @@ -122,7 +121,8 @@ fn cbc() { ); let mut result = c.clone(); - b.decrypt_bytes_b2b_mut(&c, &mut result).expect("TODO: panic message"); + b.decrypt_bytes_b2b_mut(&c, &mut result) + .expect("TODO: panic message"); assert_eq!(result, p); } @@ -160,4 +160,4 @@ fn test_zero_enc_block00() { let c = u64::from_be_bytes(p.into()); assert_eq!(c, 13290258443935467468u64); -} \ No newline at end of file +} diff --git a/b25-sys/src/bindings/arib_std_b25.rs b/b25-sys/src/bindings/arib_std_b25.rs index 74bcf77..83db6d4 100644 --- a/b25-sys/src/bindings/arib_std_b25.rs +++ b/b25-sys/src/bindings/arib_std_b25.rs @@ -5,8 +5,8 @@ #![allow(non_upper_case_globals)] #![warn(dead_code)] -use std::marker::PhantomPinned; use crate::bindings::error::BCasCardError; +use std::marker::PhantomPinned; pub const _STDINT_H: u32 = 1; pub const _FEATURES_H: u32 = 1; @@ -1304,7 +1304,6 @@ fn bindgen_test_layout_B_CAS_CARD_PRIVATE_DATA() { ); } - #[test] #[cfg(target_os = "windows")] fn bindgen_test_layout_B_CAS_CARD_PRIVATE_DATA() { @@ -1322,110 +1321,110 @@ fn bindgen_test_layout_B_CAS_CARD_PRIVATE_DATA() { unsafe { &(*(::std::ptr::null::())).mng as *const _ as usize }, 0usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(mng) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(mng) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).card as *const _ as usize }, 4usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(card) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(card) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).pool as *const _ as usize }, 8usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(pool) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(pool) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).reader as *const _ as usize }, 16usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(reader) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(reader) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).sbuf as *const _ as usize }, 24usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(sbuf) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(sbuf) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).rbuf as *const _ as usize }, 32usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(rbuf) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(rbuf) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).stat as *const _ as usize }, 40usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(stat) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(stat) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).id as *const _ as usize }, 96usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(id) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(id) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).id_max as *const _ as usize }, 112usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(id_max) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(id_max) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).pwc as *const _ as usize }, 120usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(pwc) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(pwc) ) ); assert_eq!( unsafe { &(*(::std::ptr::null::())).pwc_max as *const _ as usize }, 136usize, concat!( - "Offset of field: ", - stringify!(B_CAS_CARD_PRIVATE_DATA), - "::", - stringify!(pwc_max) + "Offset of field: ", + stringify!(B_CAS_CARD_PRIVATE_DATA), + "::", + stringify!(pwc_max) ) ); } diff --git a/b25-sys/src/bindings/ffi.rs b/b25-sys/src/bindings/ffi.rs index e1f3870..e91cdce 100644 --- a/b25-sys/src/bindings/ffi.rs +++ b/b25-sys/src/bindings/ffi.rs @@ -1,8 +1,8 @@ use std::marker::PhantomPinned; use std::ptr::null_mut; -use log::{debug, warn}; use crate::access_control::select_key_by_auth; +use log::{debug, warn}; use crate::bindings::arib_std_b25::{ wchar_t, B_CAS_CARD, B_CAS_CARD_PRIVATE_DATA, B_CAS_ECM_RESULT, B_CAS_ID, B_CAS_INIT_STATUS, @@ -100,11 +100,11 @@ unsafe extern "C" fn proc_ecm( Some(key) => { debug!("Selected Kw= {:?}", key); Ok(&payload[3..19]) - }, + } None => { warn!("No valid key found"); Err(()) - }, + } } } }; @@ -165,4 +165,3 @@ impl Default for B_CAS_CARD { } } } - diff --git a/b25-sys/src/bindings/mod.rs b/b25-sys/src/bindings/mod.rs index 555a1f2..bd2b04a 100644 --- a/b25-sys/src/bindings/mod.rs +++ b/b25-sys/src/bindings/mod.rs @@ -37,14 +37,13 @@ impl InnerDecoder { #[cfg(feature = "block00cbc")] if key { - return Self::new_with_key(dec) + return Self::new_with_key(dec); } Self::new_without_key(dec) } #[cfg(feature = "block00cbc")] - unsafe fn new_with_key(dec: *mut ARIB_STD_B25) -> Result - { + unsafe fn new_with_key(dec: *mut ARIB_STD_B25) -> Result { let mut cas = B_CAS_CARD::default(); //Allocate private data inside B_CAS_CARD cas.initialize(); @@ -55,8 +54,7 @@ impl InnerDecoder { ret.dec.as_ref().set_b_cas_card(ret.cas.as_ref().unwrap()); Ok(ret) } - unsafe fn new_without_key(dec: *mut ARIB_STD_B25) -> Result - { + unsafe fn new_without_key(dec: *mut ARIB_STD_B25) -> Result { let cas = arib_std_b25::create_b_cas_card(); if cas.is_null() { Err(AribB25DecoderError::ARIB_STD_B25_ERROR_EMPTY_B_CAS_CARD) diff --git a/b25-sys/src/lib.rs b/b25-sys/src/lib.rs index 37baec7..c97169d 100644 --- a/b25-sys/src/lib.rs +++ b/b25-sys/src/lib.rs @@ -1,9 +1,9 @@ +use futures_core::ready; use std::cell::Cell; use std::io::{Read, Write}; use std::pin::Pin; use std::sync::Mutex; use std::task::{Context, Poll}; -use futures_core::ready; pub use futures_io; use futures_io::{AsyncBufRead, AsyncRead}; @@ -95,7 +95,7 @@ impl AsyncRead for StreamDecoder<'_> { // Poll::Pending } else { //Write to this.inner in order to decode, and read from this.inner in order to write to buf - this.inner.write(recv).unwrap(); + this.inner.write_all(recv).expect("write_all failed"); this.reader.as_mut().consume(n); this.received.set(this.received.get() + n); diff --git a/recisdb-rs/src/context.rs b/recisdb-rs/src/context.rs index 12aa1ae..cd7552c 100644 --- a/recisdb-rs/src/context.rs +++ b/recisdb-rs/src/context.rs @@ -1,5 +1,5 @@ -use clap::{ArgGroup, Parser, Subcommand}; use crate::tuner_base::Voltage; +use clap::{ArgGroup, Parser, Subcommand}; #[derive(Debug, Parser)] #[clap(name = "recisdb-rs")] @@ -147,5 +147,5 @@ pub(crate) enum Commands { /// will stop. #[clap(required = true)] output: Option, - } + }, } diff --git a/recisdb-rs/src/main.rs b/recisdb-rs/src/main.rs index 087d22d..0422b1c 100644 --- a/recisdb-rs/src/main.rs +++ b/recisdb-rs/src/main.rs @@ -17,8 +17,8 @@ use crate::tuner_base::Tuned; mod channels; mod context; -mod utils; mod tuner_base; +mod utils; fn main() { let arg = context::Cli::parse(); @@ -34,7 +34,7 @@ fn main() { output, lnb, key0, - key1 + key1, } => { // Settings let settings = { @@ -54,11 +54,11 @@ fn main() { //Combine the source, decoder, and output into a single future let mut src = utils::get_src( device, - channel.map(|s| channels::Channel::from_ch_str(s)), + channel.map(channels::Channel::from_ch_str), None, - lnb + lnb, ) - .unwrap(); + .unwrap(); let from = StreamDecoder::new(&mut src, settings); let output = &mut AllowStdIo::new(utils::get_output(output).unwrap()); let (stream, abort_handle) = futures_util::io::copy_buf_abortable( @@ -72,7 +72,10 @@ fn main() { block_on(stream) } Commands::Decode { - source, key0, key1, output + source, + key0, + key1, + output, } => { // Settings let settings = { @@ -87,13 +90,7 @@ fn main() { }; //Combine the source, decoder, and output into a single future - let mut src = utils::get_src( - None, - None, - source, - None - ) - .unwrap(); + let mut src = utils::get_src(None, None, source, None).unwrap(); let from = StreamDecoder::new(&mut src, settings); let output = &mut AllowStdIo::new(utils::get_output(output).unwrap()); let (stream, abort_handle) = futures_util::io::copy_buf_abortable( @@ -108,7 +105,7 @@ fn main() { } Commands::Checksignal { device, channel } => { //open tuner and tune to channel - let channel = channel.map(|s| channels::Channel::from_ch_str(s)); + let channel = channel.map(channels::Channel::from_ch_str); let tuned = crate::tuner_base::tune(&device, channel.unwrap(), None).unwrap(); //configure sigint trigger let flag = std::sync::Arc::new(AtomicBool::new(false)); diff --git a/recisdb-rs/src/tuner_base.rs b/recisdb-rs/src/tuner_base.rs index c97b2af..83c4854 100644 --- a/recisdb-rs/src/tuner_base.rs +++ b/recisdb-rs/src/tuner_base.rs @@ -1,7 +1,7 @@ #![allow(unused_imports)] -use std::error::Error; use b25_sys::futures_io::AsyncBufRead; +use std::error::Error; use crate::channels::Channel; @@ -15,7 +15,7 @@ mod windows; pub enum Voltage { High11v, High15v, - Low + Low, } pub trait Tuned { @@ -23,7 +23,11 @@ pub trait Tuned { fn open_stream(self) -> Box; } -pub fn tune(path: &str, channel: Channel, voltage: Option) -> Result> { +pub fn tune( + path: &str, + channel: Channel, + voltage: Option, +) -> Result> { use crate::tuner_base::error::GeneralError::EnvCompatFailure; println!("{:?}", channel); cfg_if! { diff --git a/recisdb-rs/src/tuner_base/linux.rs b/recisdb-rs/src/tuner_base/linux.rs index a3c8991..4cb030c 100644 --- a/recisdb-rs/src/tuner_base/linux.rs +++ b/recisdb-rs/src/tuner_base/linux.rs @@ -1,7 +1,7 @@ +use b25_sys::futures_io::AsyncBufRead; +use futures_util::io::AllowStdIo; use std::error::Error; use std::os::unix::io::AsRawFd; -use futures_util::io::AllowStdIo; -use b25_sys::futures_io::AsyncBufRead; use crate::channels::{Channel, ChannelType, Freq}; use crate::tuner_base::Voltage; @@ -19,7 +19,12 @@ pub struct TunedDevice { channel: Channel, } impl TunedDevice { - pub fn tune(path: &str, channel: Channel, offset_k_hz: i32, voltage: Option) -> Result> { + pub fn tune( + path: &str, + channel: Channel, + offset_k_hz: i32, + voltage: Option, + ) -> Result> { let path = std::fs::canonicalize(path)?; let f = std::fs::OpenOptions::new().read(true).open(path)?; let _errno = unsafe { set_ch(f.as_raw_fd(), &channel.to_ioctl_freq(offset_k_hz))? }; @@ -50,11 +55,10 @@ impl super::Tuned for TunedDevice { match self.channel.ch_type { ChannelType::Terrestrial(_) => { let p = (5505024.0 / (raw as f64)).log10() * 10.0; - let cnr = (0.000024 * p * p * p * p) - (0.0016 * p * p * p) + (0.000024 * p * p * p * p) - (0.0016 * p * p * p) + (0.0398 * p * p) + (0.5491 * p) - + 3.0965; - cnr + + 3.0965 } _ => { const AF_LEVEL_TABLE: [f64; 14] = [ @@ -73,7 +77,7 @@ impl super::Tuned for TunedDevice { 1.420, // A0 00 40960 1.420dB 0.000, // B0 00 45056 -0.01dB ]; - let sig = ((raw & 0xFF00) >> 8) as u8 & 0xFF; + let sig = ((raw & 0xFF00) >> 8) as u8; if sig <= 0x10u8 { /* clipped maximum */ 24.07 diff --git a/recisdb-rs/src/tuner_base/windows.rs b/recisdb-rs/src/tuner_base/windows.rs index f04b476..6c04083 100644 --- a/recisdb-rs/src/tuner_base/windows.rs +++ b/recisdb-rs/src/tuner_base/windows.rs @@ -1,10 +1,10 @@ +use b25_sys::futures_io::{AsyncBufRead, AsyncRead}; +use futures_util::io::BufReader; use std::error::Error; use std::mem::ManuallyDrop; use std::ptr::NonNull; use std::task::Poll; use std::time::Duration; -use futures_util::io::BufReader; -use b25_sys::futures_io::{AsyncBufRead, AsyncRead}; use crate::channels::*; use crate::tuner_base::error::BonDriverError; @@ -105,12 +105,12 @@ impl AsyncRead for TunedDevice { buf: &mut [u8], ) -> Poll> { match self.interface.GetTsStream() { - Ok((recv, remaining)) if recv.len() > 0 => { + Ok((recv, remaining)) if !recv.is_empty() => { println!("{} bytes recv.", recv.len()); buf[0..recv.len()].copy_from_slice(&recv[0..]); Poll::Ready(Ok(buf.len())) } - Ok((recv, remaining)) if recv.len() == 0 && remaining > 0 => { + Ok((recv, remaining)) if recv.is_empty() && remaining > 0 => { println!("{} remaining.", remaining); cx.waker().wake_by_ref(); Poll::Pending diff --git a/recisdb-rs/src/utils.rs b/recisdb-rs/src/utils.rs index e76d7cc..cf7a3c4 100644 --- a/recisdb-rs/src/utils.rs +++ b/recisdb-rs/src/utils.rs @@ -1,7 +1,7 @@ -use std::{env, fs}; use std::error::Error; use std::io::Write; use std::path::{Path, PathBuf}; +use std::{env, fs}; use env_logger::Env; use futures_util::io::{AllowStdIo, BufReader}; @@ -16,7 +16,7 @@ pub(crate) fn get_src( device: Option, channel: Option, source: Option, - voltage: Option + voltage: Option, ) -> Result, Box> { if let Some(src) = device { crate::tuner_base::tune(&src, channel.unwrap(), voltage).map(|tuned| tuned.open_stream()) @@ -44,16 +44,15 @@ pub(crate) fn get_output(directory: Option) -> Result, st env::current_dir()?.to_str().unwrap(), filename_time_now ))?)) - }, - Some(path) if Path::exists(Path::new(&path))=> { + } + Some(path) if Path::exists(Path::new(&path)) => { let path = fs::canonicalize(path)?; - if fs::metadata(&path)?.is_file() - { + if fs::metadata(&path)?.is_file() { Ok(Box::new(fs::File::create(path)?)) } else { panic!("The file is directory") } - }, + } Some(path) => { let path = Path::new(&path); let path = PathBuf::from(path); @@ -74,20 +73,21 @@ pub(crate) fn parse_keys(key0: Option>, key1: Option>) - match (key0, key1) { (None, None) => false, (Some(k0), Some(k1)) => { - let k0 = k0.iter().map(|k| { - u64::from_str_radix(k.trim_start_matches("0x"), 16).unwrap() - }).collect::>(); - let k1 = k1.iter().map(|k| { - u64::from_str_radix(k.trim_start_matches("0x"), 16).unwrap() - }).collect::>(); + let k0 = k0 + .iter() + .map(|k| u64::from_str_radix(k.trim_start_matches("0x"), 16).unwrap()) + .collect::>(); + let k1 = k1 + .iter() + .map(|k| u64::from_str_radix(k.trim_start_matches("0x"), 16).unwrap()) + .collect::>(); b25_sys::set_keys(k0, k1); true - }, + } _ => panic!("Specify both of the keys"), } } -pub(crate) fn initialize_logger() -{ +pub(crate) fn initialize_logger() { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); }