/*
 * Copyright (c) 2016 Sippy Software, Inc., http://www.sippysoft.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

import "session_info.proto";
import "stream_info.proto";

enum crypto_suites {
    AES_CM_128_HMAC_SHA1_80 = 1;	/* [RFC4568] */
    AES_CM_128_HMAC_SHA1_32 = 2;	/* [RFC4568] */
    F8_128_HMAC_SHA1_80 = 3;		/* [RFC4568] */
    SEED_CTR_128_HMAC_SHA1_80 = 4;	/* [RFC5669] */
    SEED_128_CCM_80 = 5;		/* [RFC5669] */
    SEED_128_GCM_96 = 6;		/* [RFC5669] */
    AES_192_CM_HMAC_SHA1_80 = 7;	/* [RFC6188] */
    AES_192_CM_HMAC_SHA1_32 = 8;	/* [RFC6188] */
    AES_256_CM_HMAC_SHA1_80 = 9;	/* [RFC6188] */
    AES_256_CM_HMAC_SHA1_32 = 10;	/* [RFC6188] */
    AEAD_AES_128_GCM = 11;		/* [RFC7714] */
    AEAD_AES_256_GCM = 12;		/* [RFC7714] */
}

enum fec_types {
    FEC_SRTP = 1;
    SRTP_FEC = 2;
}

enum key_methods {
    km_inline = 1;			/* [RFC4568] */
}

enum srtp_session_parameters {
    UNENCRYPTED_SRTP = 1;		/* [RFC4568] */
    UNENCRYPTED_SRTCP = 2;		/* [RFC4568] */
    UNAUTHENTICATED_SRTP = 3;		/* [RFC4568] */
}

message av_u32 {
    required uint32 value = 1;
}

message fec_order {
    required fec_types fec_type = 1;
}

message fec_key {
    required string key_params = 1;
}

message session_parameters {
    oneof type {
        av_u32 kdr = 1;
        srtp_session_parameters flag = 2;
        fec_order fec_order = 3;
        fec_key fec_key = 4;
        av_u32 wsh = 5;
    }
}

message mki_params {
    required uint32 value = 1;
    required uint32 length = 2;
}

message key_info {
    required string key_salt = 1;
    optional string lifetime = 2;
    optional mki_params mki = 3;
}

/* Crypto face with respect to the RTPproxy */
message crypto_attribute_face {
    required int32 tag = 1;
    required crypto_suites suite = 2;
    required key_methods key_method = 3;
    repeated key_info keys = 4;
    repeated session_parameters session_parameters = 5;
}

message crypto_attribute {
    /* Inbound encryption, always provided */
    required crypto_attribute_face inb = 1;
    /* Outbound encryption, may be omitted for pass-through */
    optional crypto_attribute_face outb = 2;
}

message crypto_offer {
    required stream_info info = 1;
    /*
     * Offerer can put in more than one attribute and let answered to pick one
     * and signal back via tag field in the answer
     */
    repeated crypto_attribute attributes = 2;
}

message crypto_answer {
    required stream_info info = 1;

    required crypto_attribute attribute = 2;
}

message crypto_offer_bundle {
    required sess_info_offer session = 1;
    repeated crypto_offer streams = 2;
}

message crypto_answer_bundle {
    required sess_info_answer session = 1;
    repeated crypto_answer streams = 2;
}

message crypto_request {
    oneof type {
        crypto_offer_bundle offer = 1;
        crypto_answer_bundle answer = 2;
    }
}
