- print(end=" ", file=self.fh)
- print("};\n", file=self.fh)
-
- def write(self, secret):
- print("\n// secrets.h\n", file=self.fh)
- print("#ifndef SECRETS_H", file=self.fh)
- print("#define SECRETS_H\n", file=self.fh)
- print("#include <stdint.h>", file=self.fh)
- print("#include <avr/pgmspace.h>\n", file=self.fh)
- print('#include "sha1.h"\n', file=self.fh)
- self.print_as_const_sha_buf("iv", self.iv)
- self.print_as_const_sha_buf(
- "pw_mac", CryptoManager.get_hash(self.iv, self.password)
- )
- self.print_as_const(
- "secret",
- CryptoManager(self.iv, self.password).scramble(secret),
- )
- print("#endif // SECRETS_H", file=self.fh)
+ print(end=" ", file=fh)
+ print("};\n", file=fh)
+
+ @classmethod
+ def write(cls, fh, iv, pw_mac, secret):
+ print("\n// secrets.h\n", file=fh)
+ print("#ifndef SECRETS_H", file=fh)
+ print("#define SECRETS_H\n", file=fh)
+ print("#include <stdint.h>", file=fh)
+ print("#include <avr/pgmspace.h>\n", file=fh)
+ print('#include "sha1.h"\n', file=fh)
+ cls.print_as_const_sha_buf(fh, "iv", iv)
+ cls.print_as_const_sha_buf(fh, "pw_mac", pw_mac)
+ cls.print_as_const(fh, "secret", secret)
+ print("#endif // SECRETS_H", file=fh)
+
+
+def cleanup_secret(infh):
+ bio = BytesIO()
+ for line in infh:
+ line = line.strip()
+ if not line:
+ continue
+ assert len(line) < 79 and b":" in line
+ bio.write(line)
+ bio.write(b"\n")
+ return bio.getvalue()