mirror of
https://github.com/Noratrieb/cluelessh.git
synced 2026-01-14 16:35:06 +01:00
encryption
This commit is contained in:
parent
de8f5dde21
commit
e35ff86a12
10 changed files with 494 additions and 7 deletions
|
|
@ -1,16 +1,19 @@
|
|||
//! Operations on SSH keys.
|
||||
|
||||
// <https://datatracker.ietf.org/doc/html/rfc4716> exists but is kinda weird
|
||||
|
||||
use std::fmt::Display;
|
||||
|
||||
use base64::Engine;
|
||||
|
||||
use crate::parse::{self, ParseError, Parser, Writer};
|
||||
|
||||
pub enum SshPubkey {
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum PublicKey {
|
||||
Ed25519 { public_key: [u8; 32] },
|
||||
}
|
||||
|
||||
impl SshPubkey {
|
||||
impl PublicKey {
|
||||
/// Parses an SSH public key from its wire encoding as specified in
|
||||
/// RFC4253, RFC5656, and RFC8709.
|
||||
pub fn from_wire_encoding(bytes: &[u8]) -> parse::Result<Self> {
|
||||
|
|
@ -43,7 +46,7 @@ impl SshPubkey {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for SshPubkey {
|
||||
impl Display for PublicKey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::Ed25519 { .. } => {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ impl<'a> Parser<'a> {
|
|||
Self(data)
|
||||
}
|
||||
|
||||
pub fn remaining(&self) -> &[u8] {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn has_data(&self) -> bool {
|
||||
!self.0.is_empty()
|
||||
}
|
||||
|
|
@ -45,7 +49,10 @@ impl<'a> Parser<'a> {
|
|||
pub fn array<const N: usize>(&mut self) -> Result<[u8; N]> {
|
||||
assert!(N < 100_000);
|
||||
if self.0.len() < N {
|
||||
return Err(ParseError(format!("packet too short")));
|
||||
return Err(ParseError(format!(
|
||||
"packet too short, expected {N} but found {}",
|
||||
self.0.len()
|
||||
)));
|
||||
}
|
||||
let result = self.0[..N].try_into().unwrap();
|
||||
self.0 = &self.0[N..];
|
||||
|
|
@ -54,7 +61,10 @@ impl<'a> Parser<'a> {
|
|||
|
||||
pub fn slice(&mut self, len: usize) -> Result<&'a [u8]> {
|
||||
if self.0.len() < len {
|
||||
return Err(ParseError(format!("packet too short")));
|
||||
return Err(ParseError(format!(
|
||||
"packet too short, expected {len} but found {}",
|
||||
self.0.len()
|
||||
)));
|
||||
}
|
||||
if len > 100_000 {
|
||||
return Err(ParseError(format!("bytes too long: {len}")));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue