summaryrefslogtreecommitdiff
path: root/modules/srtp/sdes.c
blob: 49b32aa731697c02e980e1b6369b4e27ccfbb9ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * @file /srtp/sdes.c  SDP Security Descriptions for Media Streams (RFC 4568)
 *
 * Copyright (C) 2010 Creytiv.com
 */
#include <re.h>
#include <baresip.h>
#include "sdes.h"


const char sdp_attr_crypto[] = "crypto";


int sdes_encode_crypto(struct sdp_media *m, uint32_t tag, const char *suite,
		       const char *key, size_t key_len)
{
	return sdp_media_set_lattr(m, true, sdp_attr_crypto, "%u %s inline:%b",
				   tag, suite, key, key_len);
}


/* http://tools.ietf.org/html/rfc4568
 * a=crypto:<tag> <crypto-suite> <key-params> [<session-params>]
 */
int sdes_decode_crypto(struct crypto *c, const char *val)
{
	struct pl tag, key_prms;
	int err;

	err = re_regex(val, str_len(val), "[0-9]+ [^ ]+ [^ ]+[]*[^]*",
		       &tag, &c->suite, &key_prms, NULL, &c->sess_prms);
	if (err)
		return err;

	c->tag = pl_u32(&tag);

	c->lifetime = c->mki = pl_null;
	err = re_regex(key_prms.p, key_prms.l, "[^:]+:[^|]+[|]*[^|]*[|]*[^|]*",
		       &c->key_method, &c->key_info,
		       NULL, &c->lifetime, NULL, &c->mki);
	if (err)
		return err;

	return 0;
}