robur-coop / udns

[deprecated, developmeht moved to https://github.com/mirage/ocaml-dns] µDNS - an opinionated Domain Name System (DNS) library
BSD 2-Clause "Simplified" License
55 stars 5 forks source link

rename udns to dns #26

Closed hannesm closed 5 years ago

hannesm commented 5 years ago

//cc @avsm

@cfcs are you fine with this? tbh, I'm pretty happy to drop the U, looks much nicer imho :)

hannesm commented 5 years ago

since this will break git blame (unless there's some hidden flag to follow file renames), this may be a good opportunity to start using ocamlformat (and setup a CI job, read more), WDYT?

hannesm commented 5 years ago

I played a bit with ocamlformat: current

let find_or_generate_key key_filename bits seed =
  Bos.OS.File.exists key_filename >>= function
  | true ->
    Bos.OS.File.read key_filename >>= fun data ->
    (try Ok (X509.Encoding.Pem.Private_key.of_pem_cstruct1 (Cstruct.of_string data)) with
     | _ -> Error (`Msg "while parsing private key file"))
  | false ->
    let key =
      let g =
        match seed with
        | None -> None
        | Some seed ->
          let seed = Cstruct.of_string seed in
          Some Nocrypto.Rng.(create ~seed (module Generators.Fortuna))
      in
      `RSA (Nocrypto.Rsa.generate ?g bits)
    in
    let pem = X509.Encoding.Pem.Private_key.to_pem_cstruct1 key in
    Bos.OS.File.write ~mode:0o600 key_filename (Cstruct.to_string pem) >>= fun () ->
    Ok key

ocamlformat, profile=conventional, ocp-indent-compat

let find_or_generate_key key_filename bits seed =
  Bos.OS.File.exists key_filename >>= function
  | true -> (
      Bos.OS.File.read key_filename >>= fun data ->
      try
        Ok
          (X509.Encoding.Pem.Private_key.of_pem_cstruct1
             (Cstruct.of_string data))
      with _ -> Error (`Msg "while parsing private key file") )
  | false ->
      let key =
        let g =
          match seed with
          | None -> None
          | Some seed ->
              let seed = Cstruct.of_string seed in
              Some Nocrypto.Rng.(create ~seed (module Generators.Fortuna))
        in
        `RSA (Nocrypto.Rsa.generate ?g bits)
      in
      let pem = X509.Encoding.Pem.Private_key.to_pem_cstruct1 key in
      Bos.OS.File.write ~mode:0o600 key_filename (Cstruct.to_string pem)
      >>= fun () -> Ok key

using ocp-indent on that block (1.7.0 no configuration file, i.e. default):

let find_or_generate_key key_filename bits seed =
  Bos.OS.File.exists key_filename >>= function
  | true -> (
      Bos.OS.File.read key_filename >>= fun data ->
      try
        Ok
          (X509.Encoding.Pem.Private_key.of_pem_cstruct1
             (Cstruct.of_string data))
      with _ -> Error (`Msg "while parsing private key file") )
  | false ->
    let key =
      let g =
        match seed with
        | None -> None
        | Some seed ->
          let seed = Cstruct.of_string seed in
          Some Nocrypto.Rng.(create ~seed (module Generators.Fortuna))
      in
      `RSA (Nocrypto.Rsa.generate ?g bits)
    in
    let pem = X509.Encoding.Pem.Private_key.to_pem_cstruct1 key in
    Bos.OS.File.write ~mode:0o600 key_filename (Cstruct.to_string pem)
    >>= fun () -> Ok key

I'm not sure... I really would like a common style, but if I don't get a way to ocp-indent and ocamlformat agreeing on the layout (above: indentation of the false block of the match), I hesitate. I would like not to have to configure ocamlformat (apart from the profile=conventional, that's fine with me). any opinions?

avsm commented 5 years ago

I mainly have no opinions beyond profile=conventional seeming sensible (since i dont use ocp-indent). If they dont match, that seems to be a problem (since ocamlformat reads in ocp-indent files and tries to follow them).

Perhaps an issue on the ocamlformat tracker with the above information to get a view from upstream? /cc @gpetiot

hannesm commented 5 years ago

good point https://github.com/ocaml-ppx/ocamlformat/issues/817