Files
Cnomicon/src/libasn1/uper_put_octet.c
2021-01-22 10:16:20 -05:00

78 lines
2.6 KiB
C

/*****************************************************************************
* Copyright (C) 2004-2021
* ProbeStar Technical Systems, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
*****************************************************************************/
/*****************************************************************************
* includes
*****************************************************************************/
#include "embtypes.h"
#include "asn1uper.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define min(A,B) ((A)<(B)?(A):(B))
#define max(A,B) ((A)>(B)?(A):(B))
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* static constants
*****************************************************************************/
/*****************************************************************************
* static variables
*****************************************************************************/
/*****************************************************************************
* static prototypes
*****************************************************************************/
/*****************************************************************************
* C functions
*****************************************************************************/
void uper_put_octet_stream(UPER_Stream *uper, uint8_t *buf, uint len, uint min, uint max)
{
if (!uper || !buf || !max)
return;
// # bits
uint num = 0;
uint m = max;
while (m) {
m >>= 1;
num++;
}
if (_asn1_debug_on_)
printf("\tGET_OCTET = bits=%d, len/max=%d/%d\n", num, len, max);
// # bytes
if (min < max) {
uper_put_bits_length(uper, len, num);
}
// slurp bytes
uper_put_bytes_stream(uper, buf, len);
}