| 245 | |
| 246 | |
| 247 | class PlaintextKey(KeyBase): |
| 248 | TYPE = KeyType.PLAINTEXT |
| 249 | TYPES_ACCEPTABLE = {TYPE} |
| 250 | NAME = "plaintext" |
| 251 | ARG_NAME = "none" |
| 252 | |
| 253 | chunk_seed = 0 |
| 254 | crypt_key = b"" # makes .derive_key() work, nothing secret here |
| 255 | id_key = b"" # makes .derive_key() work, nothing secret here |
| 256 | |
| 257 | logically_encrypted = False |
| 258 | |
| 259 | @classmethod |
| 260 | def create(cls, repository, args, **kw): |
| 261 | logger.info('Encryption NOT enabled.\nUse the "--encryption=repokey|keyfile" to enable encryption.') |
| 262 | return cls(repository) |
| 263 | |
| 264 | @classmethod |
| 265 | def detect(cls, repository, manifest_data, *, other=False): |
| 266 | return cls(repository) |
| 267 | |
| 268 | def id_hash(self, data): |
| 269 | return sha256(data).digest() |
| 270 | |
| 271 | def encrypt(self, id, data): |
| 272 | return b"".join([self.TYPE_STR, data]) |
| 273 | |
| 274 | def decrypt(self, id, data): |
| 275 | self.assert_type(data[0], id) |
| 276 | return memoryview(data)[1:] |
| 277 | |
| 278 | |
| 279 | def random_blake2b_256_key(): |
no outgoing calls