6565from ._quick_query_helper import BlobQueryReader
6666from ._shared .base_client import parse_connection_str , StorageAccountHostsMixin , TransportWrapper
6767from ._shared .response_handlers import process_storage_error , return_response_headers
68+ from ._shared .validation import ChecksumAlgorithm , parse_validation_option
6869from ._serialize import (
6970 get_access_conditions ,
7071 get_api_version ,
@@ -505,15 +506,11 @@ def upload_blob(
505506 :keyword ~azure.storage.blob.ContentSettings content_settings:
506507 ContentSettings object used to set blob properties. Used to set content type, encoding,
507508 language, disposition, md5, and cache control.
508- :keyword bool validate_content:
509- If true, calculates an MD5 hash for each chunk of the blob. The storage
510- service checks the hash of the content that has arrived with the hash
511- that was sent. This is primarily valuable for detecting bitflips on
512- the wire if using http instead of https, as https (the default), will
513- already validate. Note that this MD5 hash is not stored with the
514- blob. Also note that if enabled, the memory-efficient upload algorithm
515- will not be used because computing the MD5 hash requires buffering
516- entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
509+ :keyword validate_content:
510+ Enables checksum validation for the transfer. Any checksum calculated is NOT stored with the blob.
511+ Choose "auto" (let the SDK choose the best algorithm), "crc64", or "md5". The use of bool is deprecated.
512+ NOTE: The use of "auto" or "crc64" requires the `azure-storage-extensions` package to be installed.
513+ :paramtype validate_content: Union[bool, Literal['auto', 'crc64', 'md5']]
517514 :keyword lease:
518515 Required if the blob has an active lease. If specified, upload_blob only succeeds if the
519516 blob's lease is active and matches this ID. Value can be a BlobLeaseClient object
@@ -616,6 +613,9 @@ def upload_blob(
616613 raise ValueError ("Encryption required but no key was provided." )
617614 if kwargs .get ('cpk' ) and self .scheme .lower () != 'https' :
618615 raise ValueError ("Customer provided encryption key must be used over HTTPS." )
616+ validate_content = parse_validation_option (kwargs .pop ('validate_content' , None ))
617+ if validate_content == ChecksumAlgorithm .CRC64 and self .key_encryption_key :
618+ raise ValueError ("Using encryption and content validation together is not currently supported." )
619619 options = _upload_blob_options (
620620 data = data ,
621621 blob_type = blob_type ,
@@ -627,6 +627,7 @@ def upload_blob(
627627 'key' : self .key_encryption_key ,
628628 'resolver' : self .key_resolver_function
629629 },
630+ validate_content = validate_content ,
630631 config = self ._config ,
631632 sdk_moniker = self ._sdk_moniker ,
632633 client = self ._client ,
@@ -683,15 +684,11 @@ def download_blob(
683684
684685 This keyword argument was introduced in API version '2019-12-12'.
685686
686- :keyword bool validate_content:
687- If true, calculates an MD5 hash for each chunk of the blob. The storage
688- service checks the hash of the content that has arrived with the hash
689- that was sent. This is primarily valuable for detecting bitflips on
690- the wire if using http instead of https, as https (the default), will
691- already validate. Note that this MD5 hash is not stored with the
692- blob. Also note that if enabled, the memory-efficient upload algorithm
693- will not be used because computing the MD5 hash requires buffering
694- entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
687+ :keyword validate_content:
688+ Enables checksum validation for the transfer. Any checksum calculated is NOT stored with the blob.
689+ Choose "auto" (let the SDK choose the best algorithm), "crc64", or "md5". The use of bool is deprecated.
690+ NOTE: The use of "auto" or "crc64" requires the `azure-storage-extensions` package to be installed.
691+ :paramtype validate_content: Union[bool, Literal['auto', 'crc64', 'md5']]
695692 :keyword lease:
696693 Required if the blob has an active lease. If specified, download_blob only
697694 succeeds if the blob's lease is active and matches this ID. Value can be a
@@ -765,6 +762,9 @@ def download_blob(
765762 raise ValueError ("Offset value must not be None if length is set." )
766763 if kwargs .get ('cpk' ) and self .scheme .lower () != 'https' :
767764 raise ValueError ("Customer provided encryption key must be used over HTTPS." )
765+ validate_content = parse_validation_option (kwargs .pop ('validate_content' , None ))
766+ if validate_content == ChecksumAlgorithm .CRC64 and self .key_encryption_key :
767+ raise ValueError ("Using encryption and content validation together is not currently supported." )
768768 options = _download_blob_options (
769769 blob_name = self .blob_name ,
770770 container_name = self .container_name ,
@@ -778,6 +778,7 @@ def download_blob(
778778 'key' : self .key_encryption_key ,
779779 'resolver' : self .key_resolver_function
780780 },
781+ validate_content = validate_content ,
781782 config = self ._config ,
782783 sdk_moniker = self ._sdk_moniker ,
783784 client = self ._client ,
@@ -2009,15 +2010,11 @@ def stage_block(
20092010 :param int length:
20102011 Size of the block. Optional if the length of data can be determined. For Iterable and IO, if the
20112012 length is not provided and cannot be determined, all data will be read into memory.
2012- :keyword bool validate_content:
2013- If true, calculates an MD5 hash for each chunk of the blob. The storage
2014- service checks the hash of the content that has arrived with the hash
2015- that was sent. This is primarily valuable for detecting bitflips on
2016- the wire if using http instead of https, as https (the default), will
2017- already validate. Note that this MD5 hash is not stored with the
2018- blob. Also note that if enabled, the memory-efficient upload algorithm
2019- will not be used because computing the MD5 hash requires buffering
2020- entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
2013+ :keyword validate_content:
2014+ Enables checksum validation for the transfer. Any checksum calculated is NOT stored with the blob.
2015+ Choose "auto" (let the SDK choose the best algorithm), "crc64", or "md5". The use of bool is deprecated.
2016+ NOTE: The use of "auto" or "crc64" requires the `azure-storage-extensions` package to be installed.
2017+ :paramtype validate_content: Union[bool, Literal['auto', 'crc64', 'md5']]
20212018 :keyword lease:
20222019 Required if the blob has an active lease. Value can be a BlobLeaseClient object
20232020 or the lease ID as a string.
@@ -2850,13 +2847,11 @@ def upload_page(
28502847 Required if the blob has an active lease. Value can be a BlobLeaseClient object
28512848 or the lease ID as a string.
28522849 :paramtype lease: ~azure.storage.blob.BlobLeaseClient or str
2853- :keyword bool validate_content:
2854- If true, calculates an MD5 hash of the page content. The storage
2855- service checks the hash of the content that has arrived
2856- with the hash that was sent. This is primarily valuable for detecting
2857- bitflips on the wire if using http instead of https, as https (the default),
2858- will already validate. Note that this MD5 hash is not stored with the
2859- blob.
2850+ :keyword validate_content:
2851+ Enables checksum validation for the transfer. Any checksum calculated is NOT stored with the blob.
2852+ Choose "auto" (let the SDK choose the best algorithm), "crc64", or "md5". The use of bool is deprecated.
2853+ NOTE: The use of "auto" or "crc64" requires the `azure-storage-extensions` package to be installed.
2854+ :paramtype validate_content: Union[bool, Literal['auto', 'crc64', 'md5']]
28602855 :keyword int if_sequence_number_lte:
28612856 If the blob's sequence number is less than or equal to
28622857 the specified value, the request proceeds; otherwise it fails.
@@ -3157,13 +3152,11 @@ def append_block(
31573152 :param int length:
31583153 Size of the block. Optional if the length of data can be determined. For Iterable and IO, if the
31593154 length is not provided and cannot be determined, all data will be read into memory.
3160- :keyword bool validate_content:
3161- If true, calculates an MD5 hash of the block content. The storage
3162- service checks the hash of the content that has arrived
3163- with the hash that was sent. This is primarily valuable for detecting
3164- bitflips on the wire if using http instead of https, as https (the default),
3165- will already validate. Note that this MD5 hash is not stored with the
3166- blob.
3155+ :keyword validate_content:
3156+ Enables checksum validation for the transfer. Any checksum calculated is NOT stored with the blob.
3157+ Choose "auto" (let the SDK choose the best algorithm), "crc64", or "md5". The use of bool is deprecated.
3158+ NOTE: The use of "auto" or "crc64" requires the `azure-storage-extensions` package to be installed.
3159+ :paramtype validate_content: Union[bool, Literal['auto', 'crc64', 'md5']]
31673160 :keyword int maxsize_condition:
31683161 Optional conditional header. The max length in bytes permitted for
31693162 the append blob. If the Append Block operation would cause the blob
0 commit comments