Annotation of embedaddon/strongswan/src/libstrongswan/credentials/keys/shared_key.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2007 Martin Willi
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "shared_key.h"
        !            17: 
        !            18: ENUM(shared_key_type_names, SHARED_ANY, SHARED_PPK,
        !            19:        "ANY",
        !            20:        "IKE",
        !            21:        "EAP",
        !            22:        "PRIVATE_KEY_PASS",
        !            23:        "PIN",
        !            24:        "NTLM",
        !            25:        "PPK",
        !            26: );
        !            27: 
        !            28: typedef struct private_shared_key_t private_shared_key_t;
        !            29: 
        !            30: /**
        !            31:  * private data of shared_key
        !            32:  */
        !            33: struct private_shared_key_t {
        !            34: 
        !            35:        /**
        !            36:         * public functions
        !            37:         */
        !            38:        shared_key_t public;
        !            39: 
        !            40:        /**
        !            41:         * type of this shared key
        !            42:         */
        !            43:        shared_key_type_t type;
        !            44: 
        !            45:        /**
        !            46:         * associated shared key data
        !            47:         */
        !            48:        chunk_t key;
        !            49: 
        !            50:        /**
        !            51:         * reference counter
        !            52:         */
        !            53:        refcount_t ref;
        !            54: };
        !            55: 
        !            56: METHOD(shared_key_t, get_type, shared_key_type_t,
        !            57:        private_shared_key_t *this)
        !            58: {
        !            59:        return this->type;
        !            60: }
        !            61: 
        !            62: METHOD(shared_key_t, get_key, chunk_t,
        !            63:        private_shared_key_t *this)
        !            64: {
        !            65:        return this->key;
        !            66: }
        !            67: 
        !            68: METHOD(shared_key_t, get_ref, shared_key_t*,
        !            69:        private_shared_key_t *this)
        !            70: {
        !            71:        ref_get(&this->ref);
        !            72:        return &this->public;
        !            73: }
        !            74: 
        !            75: METHOD(shared_key_t, destroy, void,
        !            76:        private_shared_key_t *this)
        !            77: {
        !            78:        if (ref_put(&this->ref))
        !            79:        {
        !            80:                free(this->key.ptr);
        !            81:                free(this);
        !            82:        }
        !            83: }
        !            84: 
        !            85: /*
        !            86:  * see header file
        !            87:  */
        !            88: shared_key_t *shared_key_create(shared_key_type_t type, chunk_t key)
        !            89: {
        !            90:        private_shared_key_t *this;
        !            91: 
        !            92:        INIT(this,
        !            93:                .public = {
        !            94:                        .get_type = _get_type,
        !            95:                        .get_key = _get_key,
        !            96:                        .get_ref = _get_ref,
        !            97:                        .destroy = _destroy,
        !            98:                },
        !            99:                .type = type,
        !           100:                .key = key,
        !           101:                .ref = 1,
        !           102:        );
        !           103: 
        !           104:        return &this->public;
        !           105: }
        !           106: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>