chiark / gitweb /
transform: add ->valid() function
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 21 Jun 2012 01:20:39 +0000 (02:20 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 12 Jul 2012 19:02:21 +0000 (20:02 +0100)
This allows outside callers to find out whether the transform has been
keyed, and can therefore relieve them of the need to track this
separately.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
secnet.h
transform.c

index b276798..6ac64e3 100644 (file)
--- a/secnet.h
+++ b/secnet.h
@@ -387,6 +387,7 @@ struct site_if {
 
 typedef struct transform_inst_if *transform_createinstance_fn(void *st);
 typedef bool_t transform_setkey_fn(void *st, uint8_t *key, int32_t keylen);
+typedef bool_t transform_valid_fn(void *st); /* 0: no key; 1: ok */
 typedef void transform_delkey_fn(void *st);
 typedef void transform_destroyinstance_fn(void *st);
 /* Returns:
@@ -400,6 +401,7 @@ typedef uint32_t transform_apply_fn(void *st, struct buffer_if *buf,
 struct transform_inst_if {
     void *st;
     transform_setkey_fn *setkey;
+    transform_valid_fn *valid;
     transform_delkey_fn *delkey;
     transform_apply_fn *forwards;
     transform_apply_fn *reverse;
index f1da564..289b02e 100644 (file)
@@ -68,6 +68,13 @@ static bool_t transform_setkey(void *sst, uint8_t *key, int32_t keylen)
     return True;
 }
 
+static bool_t transform_valid(void *sst)
+{
+    struct transform_inst *ti=sst;
+
+    return ti->keyed;
+}
+
 static void transform_delkey(void *sst)
 {
     struct transform_inst *ti=sst;
@@ -271,6 +278,7 @@ static struct transform_inst_if *transform_create(void *sst)
 
     ti->ops.st=ti;
     ti->ops.setkey=transform_setkey;
+    ti->ops.valid=transform_valid;
     ti->ops.delkey=transform_delkey;
     ti->ops.forwards=transform_forward;
     ti->ops.reverse=transform_reverse;