MCPcopy Create free account
hub / github.com/Norbyte/bg3se / SignFile

Method SignFile

CoreLib/Crypto.cpp:51–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51bool CryptoUtils::SignFile(std::wstring const& zipPath, std::wstring const& privateKeyPath)
52{
53 std::vector<uint8_t> contents;
54 std::vector<uint8_t> key;
55 if (!LoadFile(zipPath, contents)) return false;
56 if (!LoadFile(privateKeyPath, key)) return false;
57
58 if (key.size() != NUM_ECC_BYTES) return false;
59
60 PackageSignature sig;
61 memset(&sig, 0, sizeof(sig));
62 sig.Magic = PackageSignature::MAGIC_V1;
63 sig.Version = PackageSignature::VER_SIGNATURE_IN_MANIFEST;
64 sig.SignedBytes = (uint32_t)contents.size();
65
66 if (!EccSign(contents.data(), contents.size(), key.data(), sig.EccSignature)) {
67 return false;
68 }
69
70 auto contentLength = contents.size();
71 contents.resize(contentLength + sizeof(sig));
72 memcpy(contents.data() + contentLength, &sig, sizeof(sig));
73
74 return SaveFile(zipPath, contents);
75}
76
77bool CryptoUtils::GenerateKeys(std::wstring const& privateKeyPath)
78{

Callers

nothing calls this directly

Calls 5

LoadFileFunction · 0.85
SaveFileFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected