Procházet zdrojové kódy

add a Signing.from_file factory function

Malte Kraus před 8 roky
rodič
revize
4d104a0803
1 změnil soubory, kde provedl 6 přidání a 0 odebrání
  1. 6 0
      src/crypto.py

+ 6 - 0
src/crypto.py

@@ -45,6 +45,12 @@ class Signing:
         """ Generate a new private key. """
         return Signing(RSA.generate(3072).exportKey())
 
+    @classmethod
+    def from_file(cls, path):
+        """ Reads a private or public key from the file at `path`. """
+        with open(path, 'rb') as f:
+            return cls(f.read())
+
     def as_bytes(self, include_priv: bool=False) -> bytes:
         """ Serialize this key to a `bytes` value. """
         if include_priv: