b2sdk.encryption.setting

class b2sdk.encryption.setting.EncryptionKey(secret: Optional[bytes], key_id: Optional[str])[source]

Hold information about encryption key: the key itself, and its id. The id may be None, if it’s not set in encrypted file’s fileInfo. The secret may be None, if encryption metadata is read from the server.

SECRET_REPR = '******'
as_dict()[source]

Dump EncryptionKey as dict for serializing a to json for requests.

key_b64()[source]
key_md5()[source]
class b2sdk.encryption.setting.EncryptionSetting(mode: b2sdk.encryption.types.EncryptionMode, algorithm: Optional[b2sdk.encryption.types.EncryptionAlgorithm] = None, key: Optional[b2sdk.encryption.setting.EncryptionKey] = None)[source]

Hold information about encryption mode, algorithm and key (for bucket default, file version info or even upload)

serialize_to_json_for_request()[source]
as_dict()[source]

Represent the setting as a dict, for example:

{
    'mode': 'SSE-C',
    'algorithm': 'AES256',
    'customerKey': 'U3hWbVlxM3Q2djl5JEImRSlIQE1jUWZUalduWnI0dTc=',
    'customerKeyMd5': 'SWx9GFv5BTT1jdwf48Bx+Q=='
}
{
    'mode': 'SSE-B2',
    'algorithm': 'AES256'
}

or

{
    'mode': 'none'
}
add_to_upload_headers(headers)[source]
add_to_download_headers(headers)[source]
add_key_id_to_file_info(file_info: Optional[dict])[source]
class b2sdk.encryption.setting.EncryptionSettingFactory[source]
classmethod from_file_version_dict(file_version_dict: dict)b2sdk.encryption.setting.EncryptionSetting[source]

Returns EncryptionSetting for the given file_version_dict retrieved from the api

...
"serverSideEncryption": {"algorithm": "AES256", "mode": "SSE-B2"},
"fileInfo": {"sse_c_key_id": "key-identifier"}
...
classmethod from_bucket_dict(bucket_dict: dict)Optional[b2sdk.encryption.setting.EncryptionSetting][source]

Returns EncryptionSetting for the given bucket dict retrieved from the api, or None if unauthorized

Example inputs:

...
"defaultServerSideEncryption": {
    "isClientAuthorizedToRead" : true,
    "value": {
      "algorithm" : "AES256",
      "mode" : "SSE-B2"
    }
}
...

unset:

 ...
"defaultServerSideEncryption": {
    "isClientAuthorizedToRead" : true,
    "value": {
      "mode" : "none"
    }
}
...

unknown:

...
"defaultServerSideEncryption": {
    "isClientAuthorizedToRead" : false
}
...
classmethod from_response_headers(headers)[source]
b2sdk.encryption.setting.SSE_NONE = <EncryptionSetting(EncryptionMode.NONE, None, None)>

Commonly used “no encryption” setting

b2sdk.encryption.setting.SSE_B2_AES = <EncryptionSetting(EncryptionMode.SSE_B2, EncryptionAlgorithm.AES256, None)>

Commonly used SSE-B2 setting