MCPcopy Create free account
hub / github.com/antonioCoco/RogueWinRM / ASNDerWriteLength

Function ASNDerWriteLength

spnegotokenhandler/derparse.c:493–568  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491////////////////////////////////////////////////////////////////////////////
492
493int ASNDerWriteLength(unsigned char* pbData, long nLength)
494{
495 int nNumBytesRequired = ASNDerCalcNumLengthBytes(nLength);
496 int nNumLengthBytes = nNumBytesRequired - 1;
497
498
499 if (nNumBytesRequired > 1)
500 {
501
502 // Write out the number of bytes following which will be used
503 *pbData = (unsigned char)(LEN_XTND | nNumLengthBytes);
504
505 // Point to where we'll actually write the length
506 pbData++;
507
508#ifdef __LITTLE_ENDIAN__
509
510 // There may be a cleaner way to do this, but for now, this seems to be
511 // an easy way to do the transformation
512 switch (nNumLengthBytes)
513 {
514 case 1:
515 {
516 // Cast the length to a single byte, since we know that it
517 // is 0x7F or less (or we wouldn't only need a single byte).
518
519 *pbData = (unsigned char)nLength;
520 break;
521 }
522
523 case 2:
524 {
525 *pbData = *(((unsigned char*)& nLength) + 1);
526 *(pbData + 1) = *(((unsigned char*)& nLength));
527 break;
528 }
529
530 case 3:
531 {
532 *pbData = *(((unsigned char*)& nLength) + 3);
533 *(pbData + 1) = *(((unsigned char*)& nLength) + 2);
534 *(pbData + 2) = *(((unsigned char*)& nLength));
535 break;
536 }
537
538 case 4:
539 {
540 *pbData = *(((unsigned char*)& nLength) + 3);
541 *(pbData + 1) = *(((unsigned char*)& nLength) + 2);
542 *(pbData + 2) = *(((unsigned char*)& nLength) + 1);
543 *(pbData + 3) = *(((unsigned char*)& nLength));
544 break;
545 }
546
547 } // SWITCH ( nNumLengthBytes )
548
549#else
550 // We are Big-Endian, so the length can be copied in from the source

Callers 1

ASNDerWriteTokenFunction · 0.85

Calls 1

ASNDerCalcNumLengthBytesFunction · 0.85

Tested by

no test coverage detected