2
* FreeRDP: A Remote Desktop Protocol Implementation
3
* ASN.1 Basic Encoding Rules (DER)
5
* Copyright 2011 Samsung, Author Jiten Pathy
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
11
* http://www.apache.org/licenses/LICENSE-2.0
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.
24
#include <winpr/crt.h>
26
#include <freerdp/crypto/der.h>
28
int _der_skip_length(int length)
30
if (length > 0x7F && length <= 0xFF)
32
else if (length > 0xFF)
38
int der_write_length(wStream* s, int length)
40
if (length > 0x7F && length <= 0xFF)
42
Stream_Write_UINT8(s, 0x81);
43
Stream_Write_UINT8(s, length);
46
else if (length > 0xFF)
48
Stream_Write_UINT8(s, 0x82);
49
Stream_Write_UINT16_BE(s, length);
54
Stream_Write_UINT8(s, length);
59
int der_get_content_length(int length)
61
if (length > 0x81 && length <= 0x102)
63
else if (length > 0x102)
69
int der_skip_contextual_tag(int length)
71
return _der_skip_length(length) + 1;
74
int der_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc)
76
Stream_Write_UINT8(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag));
77
return der_write_length(s, length) + 1;
80
void der_write_universal_tag(wStream* s, BYTE tag, BOOL pc)
82
Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag));
85
int der_skip_octet_string(int length)
87
return 1 + _der_skip_length(length) + length;
90
void der_write_octet_string(wStream* s, BYTE* oct_str, int length)
92
der_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE);
93
der_write_length(s, length);
94
Stream_Write(s, oct_str, length);
97
int der_skip_sequence_tag(int length)
99
return 1 + _der_skip_length(length);
102
int der_write_sequence_tag(wStream* s, int length)
104
Stream_Write_UINT8(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE));
105
return der_write_length(s, length) + 1;