tembo-io / trunk

Package manager and registry for Postgres extensions
PostgreSQL License
240 stars 16 forks source link

Send Base64-encoded checksum to S3 #635

Closed theory closed 7 months ago

theory commented 7 months ago

AWS S3's object integrity just says it needs a checksum, but not the format. We were using sha256::digest(), which returned a hex string. Digging around in docs, finally revealed that it needs to be Base64-encoded.

So replace the sha256 crate with sha2 from the RustCrypto project, which provides a binary representation of a hash digest, and encode it as appropriate with the base64 and hex crates for S3 validation and Trunk download validation, respectively.

Also pass the digest around as a byte slice and let the uploader code handle encoding it into Base64 for the upload request.

Resolves TEM-2861.

theory commented 7 months ago

I've no idea why it removed async-trait from registry/Cargo.lock.

vrmiguel commented 7 months ago

Damn, good catch @theory !