Exemplo n.º 1
0
void ber_getTypeName(pstr pBuffer, int bufferLength, bertype type)
{
   ASSERT(pBuffer != NULL);

   if(IsApplicationDefinedBerType(type))
   {
#ifdef SECURE_CRT
      sprintf_s(pBuffer, bufferLength, "APPLICATION-%d", (int)(type & ~BerType_ApplicationFlag));
#else
      sprintf(pBuffer, "APPLICATION-%d", (int)(type & ~BerType_ApplicationFlag));
#endif
   }
   else if(type < BerType_LastUniversal)
   {
#ifdef SECURE_CRT
      strncpy_s(pBuffer, bufferLength, _typeNames[type], bufferLength - 1);
      pBuffer[bufferLength - 1] = 0;
#else
      strncpy(pBuffer, _typeNames[type], bufferLength);
      pBuffer[bufferLength - 1] = 0;
#endif
   }
   else
   {
      *pBuffer = 0;
   }
}
Exemplo n.º 2
0
int berReader_getRelativeOid(const BerReader *pThis, berint *pDest, int destSize)
{
   BerMemoryInput input;

   if(pThis->isContainer)
      throwError(207, "Invalid ObjectIdentifier encoding");

   ASSERT(pThis->type == BerType_RelativeOid || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   return ber_decodeRelativeOid(&input.base, pDest, destSize, pThis->length);
}
Exemplo n.º 3
0
berlong berReader_getLong(const BerReader *pThis)
{
   BerMemoryInput input;

   if(pThis->isContainer || pThis->length == 0 || byteBuffer_isEmpty(&pThis->buffer))
      throwError(203, "Invalid Integer encoding");

   ASSERT(pThis->type == BerType_Integer || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   return ber_decodeLong(&input.base, pThis->length);
}
Exemplo n.º 4
0
void berReader_getString(const BerReader *pThis, pstr pDest, int size)
{
   BerMemoryInput input;

   if(pThis->isContainer)
      throwError(205, "Invalid String encoding");

   ASSERT(pThis->type == BerType_UTF8String || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   ber_decodeString(&input.base, pDest, size < pThis->length ? size : pThis->length);
}
Exemplo n.º 5
0
double berReader_getReal(const BerReader *pThis)
{
   BerMemoryInput input;

   if(pThis->isContainer)
      throwError(204, "Invalid Real encoding");

   ASSERT(pThis->type == BerType_Real || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   return ber_decodeReal(&input.base, pThis->length);
}
Exemplo n.º 6
0
static void writeTypeTag(BerOutput *pOut, bertype type, bool isContainer)
{
   BerTag tag;
   BerClass tagClass = IsApplicationDefinedBerType(type)
                       ? BerClass_Application
                       : BerClass_Universal;

   berTag_init(&tag, tagClass, type & ~BerType_ApplicationFlag);

   if(isContainer)
      tag.preamble |= BER_CONTAINER_FLAG;

   ber_encodeTag(pOut, &tag);
}
Exemplo n.º 7
0
bool berReader_getBoolean(const BerReader *pThis)
{
   BerMemoryInput input;

   ASSERT(pThis != NULL);

   if(pThis->isContainer || pThis->length == 0 || byteBuffer_isEmpty(&pThis->buffer))
      throwError(201, "Invalid Boolean encoding");

   ASSERT(pThis->type == BerType_Boolean || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   return ber_decodeBoolean(&input.base);
}
Exemplo n.º 8
0
int berReader_getOctetString(const BerReader *pThis, byte *pDest, int size)
{
   BerMemoryInput input;
   int count;

   if(pThis->isContainer)
      throwError(206, "Invalid OctetString encoding");

   ASSERT(pThis->type == BerType_OctetString || IsApplicationDefinedBerType(pThis->type));

   berMemoryInput_init(&input, pThis->buffer.pMemory, pThis->length);

   count = size < pThis->length ? size : pThis->length;

   ber_decodeOctetString(&input.base, pDest, count);

   return count;
}