| 303 | } |
| 304 | |
| 305 | fn cmd_hex(hex_args: HexCommand) -> Result<()> { |
| 306 | fn hex_encode_io(io: &mut impl Read) -> Result<()> { |
| 307 | loop { |
| 308 | let mut buf = [0; 1024]; |
| 309 | let n = io.read(&mut buf).context("Failed to read from stdin")?; |
| 310 | if n == 0 { |
| 311 | break; |
| 312 | } |
| 313 | print!("{}", hex_fmt::HexFmt(&buf[..n])); |
| 314 | } |
| 315 | Ok(()) |
| 316 | } |
| 317 | if let Some(filename) = hex_args.filename { |
| 318 | let mut input = |
| 319 | fs::File::open(&filename).context(format!("Failed to open {}", filename))?; |
| 320 | hex_encode_io(&mut input)?; |
| 321 | } else { |
| 322 | hex_encode_io(&mut io::stdin())?; |
| 323 | }; |
| 324 | Ok(()) |
| 325 | } |
| 326 | |
| 327 | fn cmd_gen_ra_cert(args: GenRaCertArgs) -> Result<()> { |
| 328 | let ca_cert = fs::read_to_string(args.ca_cert)?; |