{"action":"created","issue":{"url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/273","labels_url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/273/labels{/name}","comments_url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/273/comments","events_url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/273/events","html_url":"https://github.com/DaGenix/rust-crypto/issues/273","id":60558659,"number":273,"title":"Assert Usage","user":{"login":"dbalchev","id":3525601,"avatar_url":"https://avatars.githubusercontent.com/u/3525601?v=3","gravatar_id":"","url":"https://api.github.com/users/dbalchev","html_url":"https://github.com/dbalchev","followers_url":"https://api.github.com/users/dbalchev/followers","following_url":"https://api.github.com/users/dbalchev/following{/other_user}","gists_url":"https://api.github.com/users/dbalchev/gists{/gist_id}","starred_url":"https://api.github.com/users/dbalchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbalchev/subscriptions","organizations_url":"https://api.github.com/users/dbalchev/orgs","repos_url":"https://api.github.com/users/dbalchev/repos","events_url":"https://api.github.com/users/dbalchev/events{/privacy}","received_events_url":"https://api.github.com/users/dbalchev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-10T19:52:43Z","updated_at":"2015-03-18T07:42:29Z","closed_at":null,"body":"`assert!` is used in many non-testing pub methods like `AesGcm::new`, `ScryptParams::new`, pub function `bcypt` and more. \r\nWouldn't it be better if those methods/function return an `Option` or `Result`, instead of crashing the task on illegal parameters?\r\n\r\nIf the team is understaffed I could help with such change if approved."},"comment":{"url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/comments/82796999","html_url":"https://github.com/DaGenix/rust-crypto/issues/273#issuecomment-82796999","issue_url":"https://api.github.com/repos/DaGenix/rust-crypto/issues/273","id":82796999,"user":{"login":"dbalchev","id":3525601,"avatar_url":"https://avatars.githubusercontent.com/u/3525601?v=3","gravatar_id":"","url":"https://api.github.com/users/dbalchev","html_url":"https://github.com/dbalchev","followers_url":"https://api.github.com/users/dbalchev/followers","following_url":"https://api.github.com/users/dbalchev/following{/other_user}","gists_url":"https://api.github.com/users/dbalchev/gists{/gist_id}","starred_url":"https://api.github.com/users/dbalchev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbalchev/subscriptions","organizations_url":"https://api.github.com/users/dbalchev/orgs","repos_url":"https://api.github.com/users/dbalchev/repos","events_url":"https://api.github.com/users/dbalchev/events{/privacy}","received_events_url":"https://api.github.com/users/dbalchev/received_events","type":"User","site_admin":false},"created_at":"2015-03-18T07:42:29Z","updated_at":"2015-03-18T07:42:29Z","body":"I like the idea of special types for passwords, keys, salts, etc even outputs, with the needed verification done in the constructor methods, so we save ourselves from getting `Result` on every single encryption/decryption/digest operation, so we don't have to propagate the `Result` when using the function inside the library. \r\n\r\nAbout `bcrypt` in particular, as a isolated function I think both returning a `Result` and accepting  verified objects as parameters will do. But how we will verify the input of say `BlockEncryptor`? If `BlockEncryptor` returns a `Result`, propagating it may/will? lead to all traits returning a `Result` on all operation. Or should we `unwrap` the result when we use these traits internally? \r\nI think we can use the verified types proposed by @marcusklaas here.\r\n\r\nAnother assert usage, I think we should discuss, is in the implementations the `Digest` and `MAC` traits. Most/all of the implementations (e.g. SHA2) have a `finished` field. `input` method asserts `!self.finished`, while the `result` method sets `finished` to true. So calling `result` and `input` without `reset`-ing first panics. Here we can use strict typing again(the `result` method consuming the object, and returning a `DigestResult` with a `reset` method). \r\n\r\n"}}