{"action":"created","issue":{"url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/89","repository_url":"https://api.github.com/repos/zonyitoo/bson-rs","labels_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/89/labels{/name}","comments_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/89/comments","events_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/89/events","html_url":"https://github.com/zonyitoo/bson-rs/issues/89","id":303384635,"node_id":"MDU6SXNzdWUzMDMzODQ2MzU=","number":89,"title":"How do I decode binary data?","user":{"login":"Svedrin","id":946488,"node_id":"MDQ6VXNlcjk0NjQ4OA==","avatar_url":"https://avatars1.githubusercontent.com/u/946488?v=4","gravatar_id":"","url":"https://api.github.com/users/Svedrin","html_url":"https://github.com/Svedrin","followers_url":"https://api.github.com/users/Svedrin/followers","following_url":"https://api.github.com/users/Svedrin/following{/other_user}","gists_url":"https://api.github.com/users/Svedrin/gists{/gist_id}","starred_url":"https://api.github.com/users/Svedrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Svedrin/subscriptions","organizations_url":"https://api.github.com/users/Svedrin/orgs","repos_url":"https://api.github.com/users/Svedrin/repos","events_url":"https://api.github.com/users/Svedrin/events{/privacy}","received_events_url":"https://api.github.com/users/Svedrin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-03-08T07:41:14Z","updated_at":"2018-06-25T15:06:50Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI'm implementing an auth mechanism based on bson and sodiumoxide, and I'm having trouble decoding the challenge. Sodiumoxide treats plaintexts as a `&[u8]`, so I'd like to use a binary string instead of a Unicode string for the challenge, but I can't seem to get `bson` to decode it correctly.\r\n\r\n**Code**\r\n\r\nWith a \"standard\" string, everything works fine:\r\n\r\n```rust\r\n#[derive(Serialize, Deserialize, Debug)]\r\npub struct AuthChallenge {\r\n    pub challenge: String,\r\n}\r\n\r\n// [...]\r\n\r\n    let challenge: AuthChallenge = bson::from_bson(\r\n        bson::Bson::Document(\r\n            bson::decode_document(\r\n                &mut Cursor::new(&message.payload[..])\r\n            ).chain_err(|| \"Could not decode bson\")?\r\n        )\r\n    ).expect(\"Decoding failed\");\r\n    info!(\"Challenge: {:?}\", challenge.challenge);\r\n```\r\n\r\nThis yields:\r\n\r\n```\r\n2018-03-08T08:22:04+01:00 - INFO - Received message ReqAuthentication (payload: [53, 0, 0, 0, 2, 99, 104, 97, 108, 108, 101, 110, 103, 101, 0, 33, 0, 0, 0, 49, 56, 55, 54, 50, 98, 57, 56, 98, 55, 99, 51, 52, 99, 50, 53, 98, 102, 57, 100, 99, 51, 49, 53, 52, 101, 52, 97, 53, 99, 97, 51, 0, 0])\r\n2018-03-08T08:22:04+01:00 - INFO - Challenge: \"18762b98b7c34c25bf9dc3154e4a5ca3\"\r\n```\r\n\r\nHowever, if I change`String` to `Vec<u8>` in the struct and change the server side to send a binary string  (`5`) instead of a standard string (`2`), I get this:\r\n\r\n```\r\n2018-03-08T08:28:12+01:00 - INFO - Received message ReqAuthentication (payload: [53, 0, 0, 0, 5, 99, 104, 97, 108, 108, 101, 110, 103, 101, 0, 32, 0, 0, 0, 0, 54, 55, 98, 54, 100, 53, 50, 99, 50, 101, 48, 51, 52, 52, 56, 49, 98, 52, 57, 101, 102, 51, 56, 56, 101, 100, 100, 54, 51, 98, 50, 102, 0])\r\nthread 'main' panicked at 'Decoding failed: InvalidType(\"a sequence\")', /checkout/src/libcore/result.rs:906:4\r\n```\r\n\r\nI'm also having trouble encoding the signature, because `to_bson` would always complain that there are no unsigned types in bson, so I ended up doing the encoding manually:\r\n\r\n```rust\r\n    bson::Bson::Binary(\r\n        bson::spec::BinarySubtype::Generic,\r\n        Vec::from(&signature[..])\r\n    )\r\n```\r\n\r\nAm I doing it wrong, or does `bson` not currently support binary strings correctly? Can I help in fixing it somehow?"},"comment":{"url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/comments/399985155","html_url":"https://github.com/zonyitoo/bson-rs/issues/89#issuecomment-399985155","issue_url":"https://api.github.com/repos/zonyitoo/bson-rs/issues/89","id":399985155,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTk4NTE1NQ==","user":{"login":"AlexFence","id":15641615,"node_id":"MDQ6VXNlcjE1NjQxNjE1","avatar_url":"https://avatars3.githubusercontent.com/u/15641615?v=4","gravatar_id":"","url":"https://api.github.com/users/AlexFence","html_url":"https://github.com/AlexFence","followers_url":"https://api.github.com/users/AlexFence/followers","following_url":"https://api.github.com/users/AlexFence/following{/other_user}","gists_url":"https://api.github.com/users/AlexFence/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexFence/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexFence/subscriptions","organizations_url":"https://api.github.com/users/AlexFence/orgs","repos_url":"https://api.github.com/users/AlexFence/repos","events_url":"https://api.github.com/users/AlexFence/events{/privacy}","received_events_url":"https://api.github.com/users/AlexFence/received_events","type":"User","site_admin":false},"created_at":"2018-06-25T15:06:50Z","updated_at":"2018-06-25T15:06:50Z","author_association":"NONE","body":"@zonyitoo by running my example I get the expected result\r\n```\r\nfence@fence-desktop ~/c/r/example> cargo r                                                                                                              master?\r\n    Finished dev [unoptimized + debuginfo] target(s) in 0.03s\r\n     Running `target/debug/example`\r\nyay!\r\n```\r\n\r\nIt appears to be working now!\r\nthank you for your quick support!"}}
{"actor":{"display_login":"AlexFence"}}