use std::io::{Read}; use std::path::Path; use std::fs::File; extern crate ssh_keys; use ssh_keys::PublicKey; fn read_file>(path: T) -> String { let mut f = File::open(path).unwrap(); let mut buf = String::with_capacity(128); f.read_to_string(&mut buf).unwrap(); return buf; } #[test] fn rsa1024() { let key = ssh_keys::openssh::parse_public_key( &read_file("test-keys/rsa1024.pub") ).unwrap(); assert_eq!(key, PublicKey::Rsa { exponent: vec![1, 0, 1], modulus: vec![0, 192, 166, 107, 240, 134, 128, 206, 93, 25, 64, 151, 249, 97, 90, 225, 72, 185, 15, 161, 178, 57, 32, 96, 20, 201, 50, 30, 49, 166, 66, 181, 82 , 234, 124, 154, 23, 127, 201, 182, 228, 79, 83, 164, 199, 85, 3, 114, 246, 43, 154, 164, 36, 97, 54, 219, 175, 9, 237, 228, 187, 112, 78, 95, 104, 96, 15, 16 , 225, 124, 214, 101, 255, 87, 58, 98, 233, 157, 15, 88, 47, 139, 43, 177, 161, 190, 188, 8, 38, 24, 168, 5, 151, 213, 104, 228, 73, 251, 66, 132, 226, 168, 224, 251, 226, 196, 49, 41, 18, 62, 98, 0, 64, 34, 235, 217, 198, 199, 85, 15, 34, 186, 199, 119, 97, 92, 117, 187, 51], }); } #[test] fn rsa1024_display() { let data = read_file("test-keys/rsa1024.pub"); let key = ssh_keys::openssh::parse_public_key(&data).unwrap(); let value = key.to_string() + " "; assert!(data.starts_with(&value)); } #[test] fn rsa2048() { let key = ssh_keys::openssh::parse_public_key( &read_file("test-keys/rsa2048.pub") ).unwrap(); assert_eq!(key, PublicKey::Rsa { exponent: vec![1, 0, 1], modulus: vec![0, 192, 101, 50, 79, 141, 108, 248, 10, 94, 98, 96, 194, 18, 175, 15, 197, 3, 157, 12, 6, 38, 64, 140, 116, 239, 139, 72, 212, 184, 101, 43, 192, 177, 48 , 165, 127, 0, 168, 245, 98, 244, 11, 159, 156, 201, 32, 203, 45, 8, 46, 230, 1, 92, 112, 123, 109, 231, 94, 44, 149, 176, 0, 55, 102, 241, 182, 95, 221, 132, 247, 83, 41, 91, 32, 62, 190, 206, 239, 93, 98, 160, 19, 19, 53, 144, 131, 71, 205, 4, 13, 203, 203, 235, 119, 135, 135, 129, 195, 31, 44, 85, 185, 93, 90, 77, 31, 148, 44, 190, 149, 98, 48, 214, 66, 191, 115, 195, 117, 47, 64, 20, 163, 7, 151, 207, 214, 26, 176, 76, 2, 161, 67, 235, 201, 134, 35, 145, 113, 134, 201, 191, 190, 20, 55, 210, 227, 206, 166, 142, 155, 109, 250, 244, 18, 238, 136, 101, 236, 43, 156, 216, 90, 94, 25, 16, 96, 228, 111, 104, 241, 62, 191, 14, 240, 215, 170, 162, 77, 167, 86, 202, 81, 254, 244, 68, 27, 87, 187, 148, 126, 66, 114, 66, 96, 220, 151, 176, 224, 224, 183, 242, 63, 104, 63, 13, 162, 200, 204, 60, 251, 7, 186, 164, 60, 79, 215, 200, 104, 60, 72, 82, 114, 181, 107, 67, 86, 56, 162, 127, 208, 199, 220, 183, 200, 65, 108, 120, 233, 198, 229, 76, 80, 91, 134, 156, 155, 189, 198, 154, 59, 89, 117, 105, 84, 199, 219], }); } #[test] fn rsa4096() { let key = ssh_keys::openssh::parse_public_key( &read_file("test-keys/rsa4096.pub") ).unwrap(); assert_eq!(key, PublicKey::Rsa { exponent: vec![1, 0, 1], modulus: vec![0, 228, 17, 247, 72, 214, 187, 146, 133, 217, 123, 30, 13, 52, 148, 172, 215, 41, 205, 83, 1, 128, 13, 205, 47, 243, 225, 93, 123, 25, 202, 50, 226, 16, 44, 9, 231, 139, 216, 175, 26, 249, 55, 143, 131, 133, 221, 23, 246, 10, 109, 179, 138, 73, 224, 210, 85, 199, 98, 58, 43, 172, 149, 11, 107, 174, 86, 117, 173, 131, 20, 55, 238, 135, 205, 5, 174, 227, 160, 184, 116, 192, 117, 210, 138, 153, 96, 37, 146, 38, 190, 11, 141, 226, 238, 201, 111, 168, 14, 110, 2, 228, 212, 48, 198, 94, 159, 110, 79, 110, 220, 149, 179, 117, 205, 12, 64, 88, 28, 211, 201, 57, 192, 181, 6, 73, 219, 129, 253, 171, 130, 76, 202, 87, 136, 107, 79, 50, 114, 232, 26, 240, 226, 124, 28, 124, 207, 22, 21, 131, 128, 1, 66, 2, 54, 117, 1, 117, 188, 159, 134, 133, 202, 31, 242, 205, 214, 115, 4, 126, 144, 105, 10, 43, 96, 66, 122, 253, 218, 128, 58, 163, 32, 35, 45, 231, 177, 104, 230, 94, 18, 186, 77, 141, 72, 91, 108, 12, 176, 41, 10, 161, 229, 2, 34, 62, 172, 71, 224, 131, 30, 5, 146, 236, 21, 139, 3, 98, 138, 207, 107, 3, 248, 150, 12, 212, 88, 204, 126, 52, 11, 128, 247, 62, 44, 68, 72, 164, 160, 18, 33, 193, 61, 198, 105, 158, 26, 157, 113, 135, 39, 201, 239, 250, 206, 148, 148, 62, 185, 62, 61, 109, 171, 236, 243, 115, 229, 47, 19, 55, 166, 163, 61, 216, 146, 225, 28, 9, 221, 18, 50, 36, 223, 128, 206, 34, 40, 116, 202, 208, 189, 95, 222, 23, 62, 243, 14, 234, 195, 20, 105, 80, 228, 93, 130, 52, 103, 234, 224, 188, 159, 11, 194, 160, 193, 134, 232, 13, 138, 228, 6, 95, 184, 52, 229, 189, 197, 253, 174, 46, 229, 61, 18, 12, 11, 238, 159, 87, 105, 129, 18, 45, 82, 127, 120, 110, 74, 140, 230, 33, 5, 72, 29, 51, 201, 133, 152, 149, 199, 158, 55, 1, 221, 69, 77, 35, 146, 229, 141, 65, 65, 116, 5, 230, 22, 146, 90, 109, 194, 190, 188, 31, 149, 128, 217, 172, 0, 5, 255, 251, 187, 184, 37, 174, 124, 162, 231, 45, 220, 247, 86, 30, 100, 235, 181, 14, 154, 75, 198, 111, 155, 225, 219, 15, 19, 172, 206, 196, 226, 46, 171, 142, 182, 153, 89, 58, 123, 30, 203, 119, 9, 214, 93, 111, 218, 162, 113, 177, 34, 139, 87, 30, 201, 210, 0, 67, 6, 58, 155, 132, 192, 155, 13, 59, 168, 255, 206, 38, 207, 138, 9, 53, 96, 177, 250, 208, 16, 38, 200, 183, 237, 81, 154, 29, 9, 182, 253, 109, 241, 185, 213, 103, 114, 168, 95, 6, 6, 243, 4, 194, 205, 83, 195, 200, 66, 46, 120, 111, 1, 27, 243, 121, 129, 146, 24, 190, 140, 237, 217, 144, 229, 98, 53], }); } #[test] fn ed25519() { let key = ssh_keys::openssh::parse_public_key( &read_file("test-keys/ed25519.pub") ).unwrap(); assert_eq!(key, PublicKey::Ed25519( [182, 135, 254, 94, 168, 107, 218, 136, 69, 10, 76, 17, 52, 204, 42, 119, 218, 188, 182, 42, 243, 239, 135, 37, 87, 29, 93, 143, 143, 19, 101, 42])); } #[test] fn ed25519_display() { let key = ssh_keys::openssh::parse_public_key( &read_file("test-keys/ed25519.pub") ).unwrap(); assert_eq!(key.to_string(), "ssh-ed25519 \ AAAAC3NzaC1lZDI1NTE5AAAAILaH/l6oa9qIRQp\ METTMKnfavLYq8++HJVcdXY+PE2Uq"); }