Struct R2ChecksumAlgorithm
- Namespace
- Cloudflare.NET.R2.Models
- Assembly
- Cloudflare.NET.R2.dll
A digest algorithm R2 verifies against the bytes of an upload, together with the request header its digest travels in and the exact number of raw bytes its digest consists of.
public readonly struct R2ChecksumAlgorithm : IEquatable<R2ChecksumAlgorithm>
- Implements
- Inherited Members
Remarks
This set is closed on purpose. R2 rejects an upload whose bytes do not hash to the digest stated in one of these headers, and that rejection is the entire value of signing the header into a presigned URL: the signature forces the client to send the digest, and R2 does the verifying. A header R2 does not verify would give a caller the impression its bytes were checked when nothing checked them, so no such header is representable here.
Verified against live R2 on 2026-08-24, by signing a digest of the wrong bytes into a presigned URL and observing the upload:
-
On a single-part PUT, R2 verifies all five algorithms: a wrong digest is rejected with 400
BadDigestand nothing is stored. -
On a multipart part upload, R2 verifies Crc32, Crc32C and
Md5 the same way, but answers 501
NotImplementedwhenever a Sha1 or Sha256 header accompanies the part, regardless of the digest's correctness. IsSupportedForPartUploads captures this split.
Properties
All
Every algorithm R2 verifies, in a fixed order suitable for enumeration and diagnostics.
public static IReadOnlyList<R2ChecksumAlgorithm> All { get; }
Property Value
Crc32
The 32-bit cyclic redundancy check (IEEE polynomial). Verified on single-part PUTs and part uploads.
public static R2ChecksumAlgorithm Crc32 { get; }
Property Value
Crc32C
The Castagnoli 32-bit cyclic redundancy check. Verified on single-part PUTs and part uploads.
public static R2ChecksumAlgorithm Crc32C { get; }
Property Value
DigestByteLength
The exact number of raw bytes a digest of this algorithm consists of, before base64 encoding.
public int DigestByteLength { get; }
Property Value
HeaderName
The request header this algorithm's digest travels in, and therefore the header a presigned URL signs.
public string HeaderName { get; }
Property Value
IsSupportedForPartUploads
Whether R2 accepts this algorithm's header on a multipart part upload. When false, R2
answers 501 NotImplemented to the part upload regardless of the digest's correctness.
public bool IsSupportedForPartUploads { get; }
Property Value
Md5
The MD5 digest. Verified on single-part PUTs and part uploads. Its digest travels in the standard
Content-MD5 header rather than an x-amz-checksum- header.
public static R2ChecksumAlgorithm Md5 { get; }
Property Value
Sha1
The SHA-1 digest. Verified on single-part PUTs; R2 answers 501 NotImplemented when this header
accompanies a part upload.
public static R2ChecksumAlgorithm Sha1 { get; }
Property Value
Sha256
The SHA-256 digest. Verified on single-part PUTs; R2 answers 501 NotImplemented when this header
accompanies a part upload.
public static R2ChecksumAlgorithm Sha256 { get; }
Property Value
Value
The lower-case wire name of the algorithm (for example "sha256").
public string Value { get; }
Property Value
Methods
Equals(R2ChecksumAlgorithm)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(R2ChecksumAlgorithm other)
Parameters
otherR2ChecksumAlgorithmAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
TryParse(string?, out R2ChecksumAlgorithm)
Resolves an algorithm from its wire name, case-insensitively.
public static bool TryParse(string? name, out R2ChecksumAlgorithm algorithm)
Parameters
namestringThe name to resolve (for example
"sha256"or"SHA256").algorithmR2ChecksumAlgorithmThe resolved algorithm, when the name matches one R2 verifies.
Returns
Operators
operator ==(R2ChecksumAlgorithm, R2ChecksumAlgorithm)
Equality by wire name, case-insensitively.
public static bool operator ==(R2ChecksumAlgorithm left, R2ChecksumAlgorithm right)
Parameters
leftR2ChecksumAlgorithmrightR2ChecksumAlgorithm
Returns
operator !=(R2ChecksumAlgorithm, R2ChecksumAlgorithm)
Inequality by wire name, case-insensitively.
public static bool operator !=(R2ChecksumAlgorithm left, R2ChecksumAlgorithm right)
Parameters
leftR2ChecksumAlgorithmrightR2ChecksumAlgorithm