@@ -19,6 +19,8 @@ use sequoia_openpgp::parse::stream::GoodChecksum;
1919use sequoia_openpgp:: serialize:: stream:: Armorer ;
2020use sequoia_openpgp:: serialize:: { Marshal , stream:: Message } ;
2121
22+ use crate :: types:: ArmorKind ;
23+
2224pub ( crate ) fn serialize < T > ( p : Packet , armor_kind : T ) -> sequoia_openpgp:: Result < Vec < u8 > >
2325where
2426 T : Into < Option < Kind > > ,
@@ -92,11 +94,32 @@ impl Decrypted {
9294 }
9395}
9496
97+ /// Wrap raw OpenPGP data in ASCII armor.
98+ ///
99+ /// Takes raw binary OpenPGP data and an `ArmorKind` specifying the armor
100+ /// header type, and returns the ASCII-armored string.
101+ #[ pyfunction]
102+ pub fn armor ( data : & [ u8 ] , kind : ArmorKind ) -> PyResult < String > {
103+ let mut output = vec ! [ ] ;
104+ {
105+ let mut writer = sequoia_openpgp:: armor:: Writer :: new ( & mut output, kind. into ( ) )
106+ . map_err ( |e| pyo3:: exceptions:: PyRuntimeError :: new_err ( e. to_string ( ) ) ) ?;
107+ std:: io:: Write :: write_all ( & mut writer, data)
108+ . map_err ( |e| pyo3:: exceptions:: PyRuntimeError :: new_err ( e. to_string ( ) ) ) ?;
109+ writer
110+ . finalize ( )
111+ . map_err ( |e| pyo3:: exceptions:: PyRuntimeError :: new_err ( e. to_string ( ) ) ) ?;
112+ }
113+ String :: from_utf8 ( output) . map_err ( |e| pyo3:: exceptions:: PyRuntimeError :: new_err ( e. to_string ( ) ) )
114+ }
115+
95116#[ pymodule]
96117pub mod pysequoia {
97118 #[ pymodule_export]
98119 pub use super :: Decrypted ;
99120 #[ pymodule_export]
121+ pub use super :: armor;
122+ #[ pymodule_export]
100123 pub use super :: cert:: Cert ;
101124 #[ pymodule_export]
102125 pub use super :: cert:: Profile ;
@@ -127,6 +150,8 @@ pub mod pysequoia {
127150 #[ pymodule_export]
128151 pub use super :: signer:: PySigner ;
129152 #[ pymodule_export]
153+ pub use super :: types:: ArmorKind ;
154+ #[ pymodule_export]
130155 pub use super :: types:: DataFormat ;
131156 #[ pymodule_export]
132157 pub use super :: types:: HashAlgorithm ;
0 commit comments