{"action":"created","issue":{"url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/54","repository_url":"https://api.github.com/repos/vbmithr/ocaml-websocket","labels_url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/54/labels{/name}","comments_url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/54/comments","events_url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/54/events","html_url":"https://github.com/vbmithr/ocaml-websocket/pull/54","id":154658205,"number":54,"title":"WIP: Parameterize RNG","user":{"login":"j0sh","id":292510,"avatar_url":"https://avatars.githubusercontent.com/u/292510?v=3","gravatar_id":"","url":"https://api.github.com/users/j0sh","html_url":"https://github.com/j0sh","followers_url":"https://api.github.com/users/j0sh/followers","following_url":"https://api.github.com/users/j0sh/following{/other_user}","gists_url":"https://api.github.com/users/j0sh/gists{/gist_id}","starred_url":"https://api.github.com/users/j0sh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/j0sh/subscriptions","organizations_url":"https://api.github.com/users/j0sh/orgs","repos_url":"https://api.github.com/users/j0sh/repos","events_url":"https://api.github.com/users/j0sh/events{/privacy}","received_events_url":"https://api.github.com/users/j0sh/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-05-13T08:22:30Z","updated_at":"2016-05-17T21:41:51Z","closed_at":"2016-05-15T13:56:10Z","pull_request":{"url":"https://api.github.com/repos/vbmithr/ocaml-websocket/pulls/54","html_url":"https://github.com/vbmithr/ocaml-websocket/pull/54","diff_url":"https://github.com/vbmithr/ocaml-websocket/pull/54.diff","patch_url":"https://github.com/vbmithr/ocaml-websocket/pull/54.patch"},"body":"Here is a patch set to allow flexibility in the choice of RNG that Websocket uses. This is done by replacing the `?g` parameter with a `?random_string` parameter of type `Rng.t = ?base64:bool -> int -> string`.\r\n\r\nThe reason for doing this is that Nocrypto is quite large (typically adds ~1MB to a native build) and pulls in a system dependency on libgmp, which is unnecessary when all that's needed is random number generation and SHA1. (Yes, this was annoying enough -- libgmp especially -- that it justified putting the effort into this.)\r\n\r\nHere, the default `random_string` has been set to use stdlib's Random, with self_init called unless otherwise specified. We use the B64 module that cohttp uses, so base64 is not an extra dependency. The only thing missing is SHA1 -- so an implementation was extracted from Uuidm, hopefully that is alright.\r\n\r\nIn addition to the Nocrypto implementation, there is also one for Cryptokit, mostly because it was easy and maybe it comes in handy for someone.\r\n\r\nMost of the real complexity in these patches comes from the build system.\r\n\r\nRNG selection is a tiny feature, so I didn't think it made sense to have separate compilation units and findlib libraries for each websocket RNG (this would probably have been implemented via functors and/or first-class modules). Tooling would have been simpler for development, but usability would have been worse on the user side. (However, I might still have missed something really obvious since I'm not really familiar with anything outside of Makefiles.)\r\n\r\nSo I went the hard way implementation-wise, in the hopes it'd be easier usability-wise. Everything is in a rng.ml{i} and conditionally compiled, ifdef-style, based on the packages available at compile time. This introduces a dependency on cppo. Then we have incantations to set up the necessary ocamlbuild tags with cppo, and the META file needs to be modified as well. I wonder if oasis would have made this simpler, since things are quite coarse with topkg.\r\n\r\nThere is also a minor fix that adds an asyc_ssl check to OPAM since that library is required for one of the tests.\r\n\r\nFeedback on the approach welcome. Also glad to scrap all this if there is a better way."},"comment":{"url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/comments/219863097","html_url":"https://github.com/vbmithr/ocaml-websocket/pull/54#issuecomment-219863097","issue_url":"https://api.github.com/repos/vbmithr/ocaml-websocket/issues/54","id":219863097,"user":{"login":"copy","id":1816456,"avatar_url":"https://avatars.githubusercontent.com/u/1816456?v=3","gravatar_id":"","url":"https://api.github.com/users/copy","html_url":"https://github.com/copy","followers_url":"https://api.github.com/users/copy/followers","following_url":"https://api.github.com/users/copy/following{/other_user}","gists_url":"https://api.github.com/users/copy/gists{/gist_id}","starred_url":"https://api.github.com/users/copy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/copy/subscriptions","organizations_url":"https://api.github.com/users/copy/orgs","repos_url":"https://api.github.com/users/copy/repos","events_url":"https://api.github.com/users/copy/events{/privacy}","received_events_url":"https://api.github.com/users/copy/received_events","type":"User","site_admin":false},"created_at":"2016-05-17T21:41:51Z","updated_at":"2016-05-17T21:41:51Z","body":"I was thinking of breaking the spec, but now that I think about it again it doesn't sound like a great idea. How about using `/dev/urandom` (reading 4 bytes for every frame)?"}}