2011-07-04 06:47:35 +04:00
|
|
|
/**
|
2012-02-21 09:56:55 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-04 06:47:35 +04:00
|
|
|
* ASN.1 Basic Encoding Rules (BER)
|
|
|
|
*
|
2012-02-21 09:56:55 +04:00
|
|
|
* Copyright 2011-2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-07-04 06:47:35 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#ifndef FREERDP_CRYPTO_BER_H
|
|
|
|
#define FREERDP_CRYPTO_BER_H
|
2011-07-04 06:47:35 +04:00
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#include <freerdp/api.h>
|
2011-07-07 23:35:09 +04:00
|
|
|
#include <freerdp/types.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
|
|
|
|
#include <winpr/stream.h>
|
2011-07-04 06:47:35 +04:00
|
|
|
|
|
|
|
/* BER type */
|
|
|
|
|
|
|
|
/* Class - bits 8 and 7 */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define BER_CLASS_MASK 0xC0
|
|
|
|
#define BER_CLASS_UNIV 0x00 /* 0 0 */
|
|
|
|
#define BER_CLASS_APPL 0x40 /* 0 1 */
|
|
|
|
#define BER_CLASS_CTXT 0x80 /* 1 0 */
|
|
|
|
#define BER_CLASS_PRIV 0xC0 /* 1 1 */
|
2011-07-04 06:47:35 +04:00
|
|
|
|
|
|
|
/* P/C - bit 6 */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define BER_PC_MASK 0x20
|
|
|
|
#define BER_PRIMITIVE 0x00 /* 0 */
|
|
|
|
#define BER_CONSTRUCT 0x20 /* 1 */
|
2011-07-04 06:47:35 +04:00
|
|
|
|
|
|
|
/* Tag - bits 5 to 1 */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define BER_TAG_MASK 0x1F
|
|
|
|
#define BER_TAG_BOOLEAN 0x01
|
|
|
|
#define BER_TAG_INTEGER 0x02
|
|
|
|
#define BER_TAG_BIT_STRING 0x03
|
|
|
|
#define BER_TAG_OCTET_STRING 0x04
|
|
|
|
#define BER_TAG_OBJECT_IDENFIER 0x06
|
|
|
|
#define BER_TAG_ENUMERATED 0x0A
|
|
|
|
#define BER_TAG_SEQUENCE 0x10
|
|
|
|
#define BER_TAG_SEQUENCE_OF 0x10
|
2011-07-04 06:47:35 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define BER_PC(_pc) (_pc ? BER_CONSTRUCT : BER_PRIMITIVE)
|
2011-07-13 05:43:52 +04:00
|
|
|
|
2014-12-01 15:12:51 +03:00
|
|
|
#ifdef __cplusplus
|
2019-11-06 17:24:51 +03:00
|
|
|
extern "C"
|
|
|
|
{
|
2014-12-01 15:12:51 +03:00
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_API BOOL ber_read_length(wStream* s, size_t* length);
|
|
|
|
FREERDP_API size_t ber_write_length(wStream* s, size_t length);
|
|
|
|
FREERDP_API size_t _ber_sizeof_length(size_t length);
|
|
|
|
FREERDP_API BOOL ber_read_universal_tag(wStream* s, BYTE tag, BOOL pc);
|
|
|
|
FREERDP_API size_t ber_write_universal_tag(wStream* s, BYTE tag, BOOL pc);
|
|
|
|
FREERDP_API BOOL ber_read_application_tag(wStream* s, BYTE tag, size_t* length);
|
|
|
|
FREERDP_API void ber_write_application_tag(wStream* s, BYTE tag, size_t length);
|
|
|
|
FREERDP_API BOOL ber_read_enumerated(wStream* s, BYTE* enumerated, BYTE count);
|
|
|
|
FREERDP_API void ber_write_enumerated(wStream* s, BYTE enumerated, BYTE count);
|
|
|
|
FREERDP_API BOOL ber_read_contextual_tag(wStream* s, BYTE tag, size_t* length, BOOL pc);
|
|
|
|
FREERDP_API size_t ber_write_contextual_tag(wStream* s, BYTE tag, size_t length, BOOL pc);
|
|
|
|
FREERDP_API size_t ber_sizeof_contextual_tag(size_t length);
|
|
|
|
FREERDP_API BOOL ber_read_sequence_tag(wStream* s, size_t* length);
|
|
|
|
FREERDP_API size_t ber_write_sequence_tag(wStream* s, size_t length);
|
|
|
|
FREERDP_API size_t ber_sizeof_sequence(size_t length);
|
|
|
|
FREERDP_API size_t ber_sizeof_sequence_tag(size_t length);
|
|
|
|
FREERDP_API BOOL ber_read_bit_string(wStream* s, size_t* length, BYTE* padding);
|
2022-01-22 17:01:43 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_API BOOL ber_read_octet_string_tag(wStream* s, size_t* length);
|
2022-01-22 17:01:43 +03:00
|
|
|
FREERDP_API BOOL ber_read_octet_string(wStream* s, BYTE** content, size_t* length);
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_API size_t ber_write_octet_string_tag(wStream* s, size_t length);
|
|
|
|
FREERDP_API size_t ber_sizeof_octet_string(size_t length);
|
2022-01-22 17:01:43 +03:00
|
|
|
FREERDP_API size_t ber_sizeof_contextual_octet_string(size_t length);
|
|
|
|
FREERDP_API size_t ber_write_char_to_unicode_octet_string(wStream* s, const char* str);
|
|
|
|
FREERDP_API size_t ber_write_contextual_char_to_unicode_octet_string(wStream* s, BYTE tag,
|
|
|
|
const char* oct_str);
|
|
|
|
FREERDP_API size_t ber_write_octet_string(wStream* s, const BYTE* oct_str, size_t length);
|
|
|
|
FREERDP_API BOOL ber_read_char_from_unicode_octet_string(wStream* s, char** str);
|
|
|
|
FREERDP_API BOOL ber_read_unicode_octet_string(wStream* s, LPWSTR* str);
|
|
|
|
FREERDP_API size_t ber_write_contextual_octet_string(wStream* s, BYTE tag, const BYTE* oct_str,
|
|
|
|
size_t length);
|
|
|
|
FREERDP_API size_t ber_write_contextual_unicode_octet_string(wStream* s, BYTE tag, LPWSTR str);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_API BOOL ber_read_BOOL(wStream* s, BOOL* value);
|
|
|
|
FREERDP_API void ber_write_BOOL(wStream* s, BOOL value);
|
|
|
|
FREERDP_API BOOL ber_read_integer(wStream* s, UINT32* value);
|
|
|
|
FREERDP_API size_t ber_write_integer(wStream* s, UINT32 value);
|
2022-01-22 17:01:43 +03:00
|
|
|
FREERDP_API size_t ber_write_contextual_integer(wStream* s, BYTE tag, UINT32 value);
|
2019-11-06 17:24:51 +03:00
|
|
|
FREERDP_API BOOL ber_read_integer_length(wStream* s, size_t* length);
|
|
|
|
FREERDP_API size_t ber_sizeof_integer(UINT32 value);
|
2022-01-22 17:01:43 +03:00
|
|
|
FREERDP_API size_t ber_sizeof_contextual_integer(UINT32 value);
|
2011-07-04 06:47:35 +04:00
|
|
|
|
2014-12-01 15:12:51 +03:00
|
|
|
#ifdef __cplusplus
|
2018-01-17 10:12:54 +03:00
|
|
|
}
|
2014-12-01 15:12:51 +03:00
|
|
|
#endif
|
|
|
|
|
2012-02-21 09:56:55 +04:00
|
|
|
#endif /* FREERDP_CRYPTO_BER_H */
|