commit 2c6ad26a6f6d4078ecf44f5641c5f47056c67a6f
parent 57172c240d9b36864db942d22f16d747f5baad75
Author: lash <dev@holbrook.no>
Date: Sun, 2 Mar 2025 14:50:18 +0000
Add cert tests
Diffstat:
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/src/lq/cert.c b/src/lq/cert.c
@@ -54,6 +54,32 @@ void lq_certificate_set_domain(LQCert *cert, const char *domain) {
lq_cpy(cert->domain, domain, LQ_CERT_DOMAIN_LEN);
}
+int lq_certificate_sign(LQCert *cert, LQPrivKey *pk) {
+ if (cert->response != NULL) {
+ if (cert->response_sig != NULL) {
+ return ERR_RESPONSE;
+ }
+ if (cert->request == NULL) {
+ return ERR_INIT;
+ }
+ cert->response_sig = lq_msg_sign(cert->response, pk);
+ if (cert->response_sig == NULL) {
+ return ERR_ENCODING;
+ }
+ }
+ if (cert->request == NULL) {
+ return ERR_INIT;
+ }
+ if (cert->request->signature != NULL) {
+ return ERR_REQUEST;
+ }
+ cert->request->sig = lq_msg_sign(cert->request, pk);
+ if (cert->request_sig == NULL) {
+ return ERR_ENCODING;
+ }
+ return ERR_OK;
+}
+
int lq_certificate_serialize(LQCert *cert, char *out, size_t *out_len) {
size_t c;
int r;
diff --git a/src/lq/cert.h b/src/lq/cert.h
@@ -24,6 +24,7 @@ struct lq_certificate_t {
LQCert* lq_certificate_new(LQCert *parent, LQCtx *ctx, LQMsg *req, LQMsg *rsp);
void lq_certificate_set_domain(LQCert *cert, const char *domain);
+int lq_certificate_sign(LQCert *cert, LQPrivKey *pk);
int lq_certificate_serialize(LQCert *cert, char *out, size_t *out_len);
int lq_certificate_deserialize(LQCert **cert, char *in, size_t in_len);
int lq_certificate_verify(LQCert *cert);
diff --git a/src/lq/err.h b/src/lq/err.h
@@ -9,6 +9,8 @@ enum err_e {
ERR_READ,
ERR_WRITE,
ERR_ENCODING,
+ ERR_REQUEST,
+ ERR_RESPONSE,
};
typedef enum err_e LQErr;