11use std:: io;
22use std:: io:: { Read , Write } ;
33
4- use bouncycastle:: hex;
54use bouncycastle:: base64;
5+ use bouncycastle:: hex;
66
77pub ( crate ) fn hex_encode_cmd ( ) {
88 // Stream from stdin to stdout in chunks of 1 kb
99 let mut buf: [ u8 ; 1024 ] = [ 0u8 ; 1024 ] ;
1010 let mut bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
1111 while bytes_read != 0 {
12- io:: stdout ( ) . write_all (
13- hex:: encode ( & buf[ ..bytes_read] ) . as_bytes ( )
14- ) . expect ( "Failed to write to stdout" ) ;
12+ io:: stdout ( )
13+ . write_all ( hex:: encode ( & buf[ ..bytes_read] ) . as_bytes ( ) )
14+ . expect ( "Failed to write to stdout" ) ;
1515
1616 bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
1717 }
@@ -22,13 +22,12 @@ pub(crate) fn hex_decode_cmd() {
2222 let mut buf: [ u8 ; 1024 ] = [ 0u8 ; 1024 ] ;
2323 let mut bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
2424 while bytes_read != 0 {
25- let chunk_str: String = String :: from_utf8 (
26- Vec :: from ( & buf[ ..bytes_read] )
27- ) . expect ( "Input was not valid utf8." ) ;
25+ let chunk_str: String =
26+ String :: from_utf8 ( Vec :: from ( & buf[ ..bytes_read] ) ) . expect ( "Input was not valid utf8." ) ;
2827
29- io:: stdout ( ) . write_all (
30- & * hex:: decode ( chunk_str. as_str ( ) ) . expect ( "Input was not valid hex." )
31- ) . expect ( "Failed to write to stdout" ) ;
28+ io:: stdout ( )
29+ . write_all ( & * hex:: decode ( chunk_str. as_str ( ) ) . expect ( "Input was not valid hex." ) )
30+ . expect ( "Failed to write to stdout" ) ;
3231
3332 bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
3433 }
@@ -40,9 +39,9 @@ pub(crate) fn base64_encode_cmd() {
4039 let mut buf: [ u8 ; 1024 ] = [ 0u8 ; 1024 ] ;
4140 let mut bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
4241 while bytes_read != 0 {
43- io:: stdout ( ) . write_all (
44- encoder. do_update ( & buf[ ..bytes_read] ) . as_bytes ( )
45- ) . expect ( "Failed to write to stdout" ) ;
42+ io:: stdout ( )
43+ . write_all ( encoder. do_update ( & buf[ ..bytes_read] ) . as_bytes ( ) )
44+ . expect ( "Failed to write to stdout" ) ;
4645
4746 bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
4847 }
@@ -54,14 +53,18 @@ pub(crate) fn base64_decode_cmd() {
5453 let mut decoder = base64:: Base64Decoder :: new ( true ) ;
5554 let mut bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
5655 while bytes_read != 0 {
57- let chunk_str: String = String :: from_utf8 (
58- Vec :: from ( & buf[ ..bytes_read] )
59- ) . expect ( "Input was not valid utf8." ) ;
56+ let chunk_str: String =
57+ String :: from_utf8 ( Vec :: from ( & buf[ ..bytes_read] ) ) . expect ( "Input was not valid utf8." ) ;
6058
61- io:: stdout ( ) . write_all (
62- decoder. do_update ( chunk_str. as_str ( ) ) . expect ( "Input was not valid base64." ) . as_slice ( )
63- ) . expect ( "Failed to write to stdout" ) ;
59+ io:: stdout ( )
60+ . write_all (
61+ decoder
62+ . do_update ( chunk_str. as_str ( ) )
63+ . expect ( "Input was not valid base64." )
64+ . as_slice ( ) ,
65+ )
66+ . expect ( "Failed to write to stdout" ) ;
6467
6568 bytes_read = io:: stdin ( ) . read ( & mut buf) . expect ( "Failed to read from stdin" ) ;
6669 }
67- }
70+ }
0 commit comments