diff options
author | Justus Winter <justus@pep-project.org> | 2018-01-04 16:06:03 +0100 |
---|---|---|
committer | Justus Winter <justus@pep-project.org> | 2018-01-04 16:06:03 +0100 |
commit | 49d10c39ab85d54d440b57522fcfdcce13f9af3f (patch) | |
tree | f01b0c27e7236ec932ad4bbe371b5c849bc10a95 /net | |
parent | 2fae25588511f14111dbe9f0465f6bf707649cee (diff) |
net: Fix sending keys to servers.
- Now that TPKs can be serialized, KeyServer::send can get actual
TPKs to send.
Diffstat (limited to 'net')
-rw-r--r-- | net/src/lib.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/net/src/lib.rs b/net/src/lib.rs index bab1b8ff..f93608fe 100644 --- a/net/src/lib.rs +++ b/net/src/lib.rs @@ -181,15 +181,19 @@ impl KeyServer { } /// Sends the given key to the server. - /// - /// XXX: This should take a &TPK, but TPKs cannot be serialized at - /// the moment. - pub fn send(&mut self, key: &[u8]) -> Result<()> { + pub fn send(&mut self, key: &TPK) -> Result<()> { + use openpgp::armor::{Writer, Kind}; + let uri = format!("{}/pks/add", self.uri).parse()?; + let mut armored_blob = vec![]; + { + let mut w = Writer::new(&mut armored_blob, Kind::PublicKey); + key.serialize(&mut w)?; + } // Prepare to send url-encoded data. let mut post_data = b"keytext=".to_vec(); - post_data.extend_from_slice(percent_encode(key, KEYSERVER_ENCODE_SET) + post_data.extend_from_slice(percent_encode(&armored_blob, KEYSERVER_ENCODE_SET) .collect::<String>().as_bytes()); let mut request = Request::new(Method::Post, uri); |