Added a keymat_t version to cast it safely
authorMartin Willi <martin@revosec.ch>
Wed, 21 Dec 2011 11:13:43 +0000 (12:13 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:31:30 +0000 (17:31 +0100)
src/libcharon/sa/ikev1/keymat_v1.c
src/libcharon/sa/ikev2/keymat_v2.c
src/libcharon/sa/keymat.h

index 100c952..a0dbd52 100644 (file)
@@ -946,6 +946,12 @@ METHOD(keymat_v1_t, confirm_iv, void,
        }
 }
 
+METHOD(keymat_t, get_version, ike_version_t,
+       private_keymat_v1_t *this)
+{
+       return IKEV1;
+}
+
 METHOD(keymat_t, create_dh, diffie_hellman_t*,
        private_keymat_v1_t *this, diffie_hellman_group_t group)
 {
@@ -984,6 +990,7 @@ keymat_v1_t *keymat_v1_create(bool initiator)
        INIT(this,
                .public = {
                        .keymat = {
+                               .get_version = _get_version,
                                .create_dh = _create_dh,
                                .get_aead = _get_aead,
                                .destroy = _destroy,
index aacff0a..3adceee 100644 (file)
@@ -71,6 +71,12 @@ struct private_keymat_v2_t {
        chunk_t skp_verify;
 };
 
+METHOD(keymat_t, get_version, ike_version_t,
+       private_keymat_v2_t *this)
+{
+       return IKEV2;
+}
+
 METHOD(keymat_t, create_dh, diffie_hellman_t*,
        private_keymat_v2_t *this, diffie_hellman_group_t group)
 {
@@ -563,6 +569,7 @@ keymat_v2_t *keymat_v2_create(bool initiator)
        INIT(this,
                .public = {
                        .keymat = {
+                               .get_version = _get_version,
                                .create_dh = _create_dh,
                                .get_aead = _get_aead,
                                .destroy = _destroy,
index 4a551a8..9de2574 100644 (file)
@@ -37,6 +37,13 @@ typedef struct keymat_t keymat_t;
 struct keymat_t {
 
        /**
+        * Get IKE version of this keymat.
+        *
+        * @return                      IKEV1 for keymat_v1_t, IKEV2 for keymat_v2_t
+        */
+       ike_version_t (*get_version)(keymat_t *this);
+
+       /**
         * Create a diffie hellman object for key agreement.
         *
         * The diffie hellman is either for IKE negotiation/rekeying or