def test_encrypt_decrypt(self): """Test a roundtrip in the encryption/decryption code""" origin = "AAAAAAAA" key = os.urandom(32) aad = os.urandom(32) clearstr = sops.decrypt(sops.encrypt(origin, key, aad=aad), key, aad=aad) assert clearstr == origin
def enc(file, remove=False): """ Encrypts the given file in its directory If the file is already encrypted, a corresponding secrets.yaml.dec will be encrypted to the original file location. """ if sops.is_enc(file): if os.path.isfile(__decfile(file)) \ and not sops.is_enc(__decfile(file)): # we can encrypt the .dec.yaml file with open(file, "w") as of: sops.encrypt(__decfile(file), inplace=False, outfile=of) if remove: os.remove(__decfile(file)) else: raise FileExistsError("file is already encrypted") else: if __is_decfile(file): with open(__encfile(file), "w") as of: sops.encrypt(file, inplace=False, outfile=of) else: file = __encfile(file) sops.encrypt(file)
def test_encrypt(self): """Test encrypt return a encrypted value.""" cryptstr = sops.encrypt("AAAAAAA", os.urandom(32)) assert cryptstr.startswith("ENC[AES256_GCM,data:") assert cryptstr[-1:] == "]"