~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp/crypto/der.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.1.9) (9.1.17 sid)
  • Revision ID: package-import@ubuntu.com-20141111122050-wyr8hrnwco9fcmum
Tags: 1.1.0~git20140921.1.440916e+dfsg1-2ubuntu1
* Merge with Debian unstable, remaining changes
  - Disable ffmpeg support
* Disable gstreamer support, this relies on gstreamer 0.10 and we don't want
  to add any more deps on that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Implementation
 
3
 * ASN.1 Basic Encoding Rules (DER)
 
4
 *
 
5
 * Copyright 2011 Samsung, Author Jiten Pathy
 
6
 *
 
7
 * Licensed under the Apache License, Version 2.0 (the "License");
 
8
 * you may not use this file except in compliance with the License.
 
9
 * You may obtain a copy of the License at
 
10
 *
 
11
 *       http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing, software
 
14
 * distributed under the License is distributed on an "AS IS" BASIS,
 
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 * See the License for the specific language governing permissions and
 
17
 * limitations under the License.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include "config.h"
 
22
#endif
 
23
 
 
24
#include <winpr/crt.h>
 
25
 
 
26
#include <freerdp/crypto/der.h>
 
27
 
 
28
int _der_skip_length(int length)
 
29
{
 
30
        if (length > 0x7F && length <= 0xFF)
 
31
                return 2;
 
32
        else if (length > 0xFF)
 
33
                return 3;
 
34
        else
 
35
                return 1;
 
36
}
 
37
 
 
38
int der_write_length(wStream* s, int length)
 
39
{
 
40
        if (length > 0x7F && length <= 0xFF)
 
41
        {
 
42
                Stream_Write_UINT8(s, 0x81);
 
43
                Stream_Write_UINT8(s, length);
 
44
                return 2;
 
45
        }
 
46
        else if (length > 0xFF)
 
47
        {
 
48
                Stream_Write_UINT8(s, 0x82);
 
49
                Stream_Write_UINT16_BE(s, length);
 
50
                return 3;
 
51
        }
 
52
        else
 
53
        {
 
54
                Stream_Write_UINT8(s, length);
 
55
                return 1;
 
56
        }
 
57
}
 
58
 
 
59
int der_get_content_length(int length)
 
60
{
 
61
        if (length > 0x81 && length <= 0x102)
 
62
                return length - 3;
 
63
        else if (length > 0x102)
 
64
                return length - 4;
 
65
        else
 
66
                return length - 2;
 
67
}
 
68
 
 
69
int der_skip_contextual_tag(int length)
 
70
{
 
71
        return _der_skip_length(length) + 1;
 
72
}
 
73
 
 
74
int der_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc)
 
75
{
 
76
        Stream_Write_UINT8(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag));
 
77
        return der_write_length(s, length) + 1;
 
78
}
 
79
 
 
80
void der_write_universal_tag(wStream* s, BYTE tag, BOOL pc)
 
81
{
 
82
        Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag));
 
83
}
 
84
 
 
85
int der_skip_octet_string(int length)
 
86
{
 
87
        return 1 + _der_skip_length(length) + length;
 
88
}
 
89
 
 
90
void der_write_octet_string(wStream* s, BYTE* oct_str, int length)
 
91
{
 
92
        der_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE);
 
93
        der_write_length(s, length);
 
94
        Stream_Write(s, oct_str, length);
 
95
}
 
96
 
 
97
int der_skip_sequence_tag(int length)
 
98
{
 
99
        return 1 + _der_skip_length(length);
 
100
}
 
101
 
 
102
int der_write_sequence_tag(wStream* s, int length)
 
103
{
 
104
        Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE));
 
105
        return der_write_length(s, length) + 1;
 
106
}
 
107