MCPcopy Create free account
hub / github.com/cuberite/cuberite / DigestToJava

Method DigestToJava

src/Crypto.cpp:460–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

458
459
460void cSHA1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out)
461{
462 Checksum Digest;
463 memcpy(Digest, a_Digest, sizeof(Digest));
464
465 bool IsNegative = (Digest[0] >= 0x80);
466 if (IsNegative)
467 {
468 // Two's complement:
469 bool carry = true; // Add one to the whole number
470 for (int i = 19; i >= 0; i--)
471 {
472 Digest[i] = ~Digest[i];
473 if (carry)
474 {
475 carry = (Digest[i] == 0xff);
476 Digest[i]++;
477 }
478 }
479 }
480 a_Out.clear();
481 a_Out.reserve(40);
482 for (int i = 0; i < 20; i++)
483 {
484 AppendPrintf(a_Out, "%02x", Digest[i]);
485 }
486 while ((a_Out.length() > 0) && (a_Out[0] == '0'))
487 {
488 a_Out.erase(0, 1);
489 }
490 if (IsNegative)
491 {
492 a_Out.insert(0, "-");
493 }
494}
495
496
497

Callers

nothing calls this directly

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected