| 677 | return str(path) |
| 678 | |
| 679 | def load(self, target, passphrase): |
| 680 | if self.STORAGE == KeyBlobStorage.KEYFILE: |
| 681 | with open(target) as fd: |
| 682 | key_data = "".join(fd.readlines()[1:]) |
| 683 | elif self.STORAGE == KeyBlobStorage.REPO: |
| 684 | # While the repository is encrypted, we consider a repokey repository with a blank |
| 685 | # passphrase an unencrypted repository. |
| 686 | self.logically_encrypted = passphrase != "" # nosec B105 |
| 687 | |
| 688 | # what we get in target is just a repo location, but we already have the repo obj: |
| 689 | target = self.repository |
| 690 | key_data = target.load_key() |
| 691 | if not key_data: |
| 692 | # if we got an empty key, it means there is no key. |
| 693 | loc = target._location.canonical_path() |
| 694 | raise RepoKeyNotFoundError(loc) from None |
| 695 | key_data = key_data.decode("utf-8") # remote repo: msgpack issue #99, getting bytes |
| 696 | else: |
| 697 | raise TypeError("Unsupported borg key storage type") |
| 698 | success = self._load(key_data, passphrase) |
| 699 | if success: |
| 700 | self.target = target |
| 701 | return success |
| 702 | |
| 703 | def save(self, target, passphrase, algorithm, create=False): |
| 704 | key_data = self._save(passphrase, algorithm) |