Initial commit of files
This commit is contained in:
79
src/libasn1/uper_get_octet.c
Normal file
79
src/libasn1/uper_get_octet.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*****************************************************************************
|
||||
* 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
|
||||
*****************************************************************************/
|
||||
|
||||
uint uper_get_octet_stream(UPER_Stream *uper, uint8_t *buf, uint min, uint max)
|
||||
{
|
||||
if (!uper || !buf || !max)
|
||||
return 0;
|
||||
|
||||
// # bits
|
||||
uint num = 0;
|
||||
uint m = max;
|
||||
while (m) {
|
||||
m >>= 1;
|
||||
num++;
|
||||
}
|
||||
|
||||
uint len = max;
|
||||
|
||||
// # bytes
|
||||
if (min < max) {
|
||||
len = uper_get_bits_length(uper, num);
|
||||
}
|
||||
|
||||
if (_asn1_debug_on_)
|
||||
printf("\tGET_OCTET = bits=%d, len/max=%d/%d\n", num, len, max);
|
||||
|
||||
// slurp bytes
|
||||
return uper_get_bytes_stream(uper, buf, len);
|
||||
}
|
||||
Reference in New Issue
Block a user