ooni / minivpn

A minimalistic OpenVPN implementation in Go
GNU General Public License v3.0
38 stars 6 forks source link

refactor(bytes): changes after code review #6

Closed bassosimone closed 2 years ago

bassosimone commented 2 years ago
  1. use math's package constants to express limits;

  2. distinguish between options encoding and decoding errors;

  3. use longer variable names when I thought the variable names were too short and hence not descriptive enough;

  4. ensure functions defined in vpn/bytes.go mention "bytes" in their name to provide readers of a clue of where they belong;

  5. decodeOptionStringFromBytes: avoid panic when byte array length is smaller than two bytes;

  6. decodeOptionStringFromBytes: reslice to simplify arithmetics;

  7. decodeOptionStringFromBytes: handle case where the peer sends a zero length encoding of options;

  8. decodeOptionStringFromBytes: handle case where \0 is missing;

  9. introduce panicIfFalse to emulate assert in golang, except that panicIfFalse is better because it cannot be disabled.

Part of https://github.com/ooni/probe/issues/2083

bassosimone commented 2 years ago

Oh, tests are broken. Let me see if I can fix them.

bassosimone commented 2 years ago

Ah, okay, it was already fixed in master, so I merged with master.

bassosimone commented 2 years ago

Thank you!