Add comments to s3.h

This commit is contained in:
2025-12-01 14:42:25 +01:00
parent abdbb2ab5b
commit e5068c43b0
2 changed files with 29 additions and 14 deletions
+5 -5
View File
@@ -541,7 +541,7 @@ int s3_presign_url(
struct tm unpacked_now;
if (unpack_time(now, &unpacked_now))
return -1; // TODO
return S3_OTHER_ERROR;
char date_buf_0[sizeof("YYYYMMDD")];
char date_buf_1[sizeof("YYYYMMDDthhmmssz")];
@@ -549,7 +549,7 @@ int s3_presign_url(
int ret = strftime(date_buf_0, sizeof(date_buf_0),
"%Y%m%d", &unpacked_now);
if (ret != sizeof(date_buf_0)-1)
return -1; // TODO
return S3_OTHER_ERROR;
S3_String yyyymmdd = {
date_buf_0,
sizeof(date_buf_0)-1
@@ -558,7 +558,7 @@ int s3_presign_url(
ret = strftime(date_buf_1, sizeof(date_buf_1),
"%Y%m%dT%H%M%SZ", &unpacked_now);
if (ret != sizeof(date_buf_1)-1)
return -1; // TODO
return S3_OTHER_ERROR;
S3_String yyyymmddthhmmssz = {
date_buf_1,
sizeof(date_buf_1)-1
@@ -567,14 +567,14 @@ int s3_presign_url(
char hash_buf[32];
if (payload.len > 0) {
if (sha256(payload.ptr, payload.len, hash_buf) < 0)
return -1;
return S3_LIB_ERROR;
}
S3_String hash = { hash_buf, sizeof(hash_buf) };
char expire_buf[11];
ret = snprintf(expire_buf, sizeof(expire_buf), "%d", expire);
if (ret < 0 || ret >= (int) sizeof(expire_buf))
return -1;
return S3_OTHER_ERROR;
S3_String expire_str = { expire_buf, ret };
for (int i = 0; i < 2; i++) {
+22 -7
View File
@@ -3,18 +3,33 @@
#include <time.h>
#define S3_S(X) (S3_String) { (X), sizeof(X)-1 }
enum {
S3_OUT_OF_MEMORY = -1,
S3_LIB_ERROR = -2,
};
typedef struct {
char *ptr;
int len;
} S3_String;
// Utility to translate string literals to S3_Strings
#define S3_S(X) (S3_String) { (X), sizeof(X)-1 }
enum {
S3_OUT_OF_MEMORY = -1,
S3_LIB_ERROR = -2,
S3_OTHER_ERROR = -3,
};
// Writes the presigned URL in the dst buffer and
// returns the number of bytes written. No more than
// "cap" bytes are ever written. On error, a negative
// status code is returned:
//
// S3_OUT_OF_MEMORY
// An allocation failed or the output buffer is too small
//
// S3_LIB_ERROR
// The underlying crypto library failed
//
// S3_OTHER_ERROR
// Some other error
int s3_presign_url(
S3_String bucket,
S3_String object,