Skip to content

Commit

Permalink
Add support for PEM files
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Aug 20, 2022
1 parent 6579928 commit a118670
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ matcher_map!(
"obj",
matchers::app::is_coff
),
(
MatcherType::App,
"application/x-x509-ca-cert",
"pem",
matchers::app::is_pem
),
// Book
(
MatcherType::Book,
Expand Down
17 changes: 17 additions & 0 deletions src/matchers/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,20 @@ pub fn is_coff_ia64(buf: &[u8]) -> bool {
pub fn is_coff(buf: &[u8]) -> bool {
is_coff_x64(buf) || is_coff_i386(buf) || is_coff_ia64(buf)
}

/// Returns whether a buffer is pem
pub fn is_pem(buf: &[u8]) -> bool {
// https://en.wikipedia.org/wiki/List_of_file_signatures
buf.len() > 11
&& buf[0] == b'-'
&& buf[1] == b'-'
&& buf[2] == b'-'
&& buf[3] == b'-'
&& buf[4] == b'-'
&& buf[5] == b'B'
&& buf[6] == b'E'
&& buf[7] == b'G'
&& buf[8] == b'I'
&& buf[9] == b'N'
&& buf[10] == b' '
}
28 changes: 28 additions & 0 deletions testdata/sample.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC99vjUBNlNDE+o
yQVGMNfA1/pRYz5xQMVw/SYfpbbk6YNtidB6nMx9UBDyRQ1J0cVjqUvFXJjuLpve
uJFrT0TSv9tg+oGPIm2itMDMsEcizZv+tTJxmZ0NFswUx+m9g0gWbGIyKYxG6rd9
vrXxVkijaxWbYKUpvXWgipPysKukh0RSTvWPDbUTUOeW7O800ZKPX2MY0vA3pGhj
CiWe/WjE9NuA2yiBOymLPi1JLFC1le4JopwV3tYtVGCCgahPTxAxNlqWI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wOKr30f4FXTG/T1fmv0aV/iJhsbNVWdQUP47gs/FKC7XStU/AS
+zkxLpe3dKF8hbwg8vk2mIxItFBxZGvoxlky2NUCgYAEBpoD68o6yR5z9/TutCZL
OisP64AcihaVFiChb8xUmqAoJhcMql//2q2L3GgviqQkddWgl4WGzDxsXgwT0DyF
IKdjsJmGgwpi5UZ0uahadk2uxQPoO+3J4/j4fvhDhNf/ZOnssNTduFebBs7Fy8i+
WFtqW1G1RcCWY3MatfhuWA==
-----END PRIVATE KEY-----
2 changes: 2 additions & 0 deletions tests/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ test_format!(
test_format!(App, "application/wasm", "wasm", wasm, "sample.wasm");

test_format!(App, "application/x-x509-ca-cert", "der", der, "sample.der");

test_format!(App, "application/x-x509-ca-cert", "pem", pem, "sample.pem");

0 comments on commit a118670

Please sign in to comment.