2012-03-06 00:45:54 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-03-06 00:45:54 +04:00
|
|
|
* ASN.1 Encoding Rules (BER/DER common functions)
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
* Modified by Jiten Pathy
|
|
|
|
*
|
|
|
|
* 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-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-06 00:45:54 +04:00
|
|
|
#include <freerdp/crypto/er.h>
|
|
|
|
#include <freerdp/crypto/ber.h>
|
|
|
|
#include <freerdp/crypto/der.h>
|
|
|
|
|
|
|
|
void er_read_length(STREAM* s, int* length)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte & 0x80)
|
|
|
|
{
|
|
|
|
byte &= ~(0x80);
|
|
|
|
|
|
|
|
if (byte == 1)
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, *length);
|
2012-03-06 00:45:54 +04:00
|
|
|
if (byte == 2)
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16_be(s, *length);
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*length = byte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write er length.
|
|
|
|
* @param s stream
|
|
|
|
* @param length length
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
int er_write_length(STREAM* s, int length, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
return der_write_length(s, length);
|
|
|
|
else
|
|
|
|
return ber_write_length(s, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int _er_skip_length(int length)
|
|
|
|
{
|
|
|
|
if (length > 0x7F)
|
|
|
|
return 3;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int er_get_content_length(int length)
|
|
|
|
{
|
|
|
|
if (length - 1 > 0x7F)
|
|
|
|
return length - 4;
|
|
|
|
else
|
|
|
|
return length - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read er Universal tag.
|
|
|
|
* @param s stream
|
|
|
|
* @param tag er universally-defined tag
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL er_read_universal_tag(STREAM* s, BYTE tag, BOOL pc)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != (ER_CLASS_UNIV | ER_PC(pc) | (ER_TAG_MASK & tag)))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write er Universal tag.
|
|
|
|
* @param s stream
|
|
|
|
* @param tag er universally-defined tag
|
2012-10-09 10:31:28 +04:00
|
|
|
* @param pc primitive (FALSE) or constructed (TRUE)
|
2012-03-06 00:45:54 +04:00
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void er_write_universal_tag(STREAM* s, BYTE tag, BOOL pc)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag));
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read er Application tag.
|
|
|
|
* @param s stream
|
|
|
|
* @param tag er application-defined tag
|
|
|
|
* @param length length
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL er_read_application_tag(STREAM* s, BYTE tag, int* length)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (tag > 30)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != ((ER_CLASS_APPL | ER_CONSTRUCT) | ER_TAG_MASK))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != tag)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
er_read_length(s, length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != ((ER_CLASS_APPL | ER_CONSTRUCT) | (ER_TAG_MASK & tag)))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
er_read_length(s, length);
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write er Application tag.
|
|
|
|
* @param s stream
|
|
|
|
* @param tag er application-defined tag
|
|
|
|
* @param length length
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void er_write_application_tag(STREAM* s, BYTE tag, int length, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
if (tag > 30)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (ER_CLASS_APPL | ER_CONSTRUCT) | ER_TAG_MASK);
|
|
|
|
stream_write_BYTE(s, tag);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, length, flag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (ER_CLASS_APPL | ER_CONSTRUCT) | (ER_TAG_MASK & tag));
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, length, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL er_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != ((ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag)))
|
|
|
|
{
|
|
|
|
stream_rewind(s, 1);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
er_read_length(s, length);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
int er_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag));
|
2012-03-06 00:45:54 +04:00
|
|
|
return er_write_length(s, length, flag) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int er_skip_contextual_tag(int length)
|
|
|
|
{
|
|
|
|
return _er_skip_length(length) + 1;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL er_read_sequence_tag(STREAM* s, int* length)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, byte);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (byte != ((ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_SEQUENCE_OF)))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
er_read_length(s, length);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write er SEQUENCE tag.
|
|
|
|
* @param s stream
|
|
|
|
* @param length length
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
int er_write_sequence_tag(STREAM* s, int length, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE));
|
2012-03-06 00:45:54 +04:00
|
|
|
return er_write_length(s, length, flag) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int er_skip_sequence(int length)
|
|
|
|
{
|
|
|
|
return 1 + _er_skip_length(length) + length;
|
|
|
|
}
|
|
|
|
|
|
|
|
int er_skip_sequence_tag(int length)
|
|
|
|
{
|
|
|
|
return 1 + _er_skip_length(length);
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL er_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
er_read_universal_tag(s, ER_TAG_ENUMERATED, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, &length);
|
|
|
|
|
|
|
|
if (length == 1)
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, *enumerated);
|
2012-03-06 00:45:54 +04:00
|
|
|
else
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
/* check that enumerated value falls within expected range */
|
|
|
|
if (*enumerated + 1 > count)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void er_write_enumerated(STREAM* s, BYTE enumerated, BYTE count, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_ENUMERATED, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, 1, flag);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, enumerated);
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BOOL er_read_bit_string(STREAM* s, int* length, BYTE* padding)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_read_universal_tag(s, ER_TAG_BIT_STRING, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, length);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, *padding);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
BOOL er_write_bit_string_tag(STREAM* s, UINT32 length, BYTE padding, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_BIT_STRING, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, length, flag);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, padding);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL er_read_octet_string(STREAM* s, int* length)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
if(!er_read_universal_tag(s, ER_TAG_OCTET_STRING, FALSE))
|
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, length);
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a er OCTET_STRING
|
|
|
|
* @param s stream
|
|
|
|
* @param oct_str octet string
|
|
|
|
* @param length string length
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
void er_write_octet_string(STREAM* s, BYTE* oct_str, int length, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, length, flag);
|
|
|
|
stream_write(s, oct_str, length);
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
int er_write_octet_string_tag(STREAM* s, int length, BOOL flag)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_write_length(s, length, flag);
|
|
|
|
return 1 + _er_skip_length(length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int er_skip_octet_string(int length)
|
|
|
|
{
|
|
|
|
return 1 + _er_skip_length(length) + length;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read a er BOOLEAN
|
|
|
|
* @param s
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL er_read_BOOL(STREAM* s, BOOL* value)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
int length;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE v;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (!er_read_universal_tag(s, ER_TAG_BOOLEAN, FALSE))
|
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, &length);
|
|
|
|
if (length != 1)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, v);
|
2012-10-09 10:31:28 +04:00
|
|
|
*value = (v ? TRUE : FALSE);
|
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a er BOOLEAN
|
|
|
|
* @param s
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
void er_write_BOOL(STREAM* s, BOOL value)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_BOOLEAN, FALSE);
|
|
|
|
er_write_length(s, 1, FALSE);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, (value == TRUE) ? 0xFF : 0);
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
BOOL er_read_integer(STREAM* s, UINT32* value)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
int length;
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
er_read_universal_tag(s, ER_TAG_INTEGER, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, &length);
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
|
|
|
stream_seek(s, length);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (length == 1)
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, *value);
|
2012-03-06 00:45:54 +04:00
|
|
|
else if (length == 2)
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16_be(s, *value);
|
2012-03-06 00:45:54 +04:00
|
|
|
else if (length == 3)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE byte;
|
|
|
|
stream_read_BYTE(s, byte);
|
|
|
|
stream_read_UINT16_be(s, *value);
|
2012-03-06 00:45:54 +04:00
|
|
|
*value += (byte << 16);
|
|
|
|
}
|
|
|
|
else if (length == 4)
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32_be(s, *value);
|
2012-03-06 00:45:54 +04:00
|
|
|
else
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-03-06 00:45:54 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write a er INTEGER
|
|
|
|
* @param s
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int er_write_integer(STREAM* s, INT32 value)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_universal_tag(s, ER_TAG_INTEGER, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
|
|
|
|
if (value <= 127 && value >= -128)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_length(s, 1, FALSE);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, value);
|
2012-03-06 00:45:54 +04:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (value <= 32767 && value >= -32768)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_length(s, 2, FALSE);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16_be(s, value);
|
2012-03-06 00:45:54 +04:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_write_length(s, 4, FALSE);
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32_be(s, value);
|
2012-03-06 00:45:54 +04:00
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
int er_skip_integer(INT32 value)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
|
|
|
if (value <= 127 && value >= -128)
|
|
|
|
{
|
|
|
|
return _er_skip_length(1) + 2;
|
|
|
|
}
|
|
|
|
else if (value <= 32767 && value >= -32768)
|
|
|
|
{
|
|
|
|
return _er_skip_length(2) + 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return _er_skip_length(4) + 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL er_read_integer_length(STREAM* s, int* length)
|
2012-03-06 00:45:54 +04:00
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
er_read_universal_tag(s, ER_TAG_INTEGER, FALSE);
|
2012-03-06 00:45:54 +04:00
|
|
|
er_read_length(s, length);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-03-06 00:45:54 +04:00
|
|
|
}
|