Skip to content

Commit 7ea536f

Browse files
committed
Narinfo sign: multiple signatures variant
This is a small optimization used when we're signing a narinfo for multiple keys in one go. Using this sign variant, we only compute the NAR fingerprint once, then sign it with all the keys.
1 parent e12369a commit 7ea536f

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/libstore/binary-cache-store.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
279279
stats.narWriteCompressedBytes += fileSize;
280280
stats.narWriteCompressionTimeMs += duration;
281281

282-
for (auto &signer: signers) {
283-
narInfo->sign(*this, *signer);
284-
}
282+
narInfo->sign(*this, signers);
285283

286284
/* Atomically write the NAR info file.*/
287285
writeNarInfo(narInfo);

src/libstore/include/nix/store/path-info.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct ValidPathInfo : UnkeyedValidPathInfo {
144144
std::string fingerprint(const Store & store) const;
145145

146146
void sign(const Store & store, const Signer & signer);
147+
void sign(const Store & store, const std::vector<std::unique_ptr<Signer>> & signers);
147148

148149
/**
149150
* @return The `ContentAddressWithReferences` that determines the

src/libstore/path-info.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ void ValidPathInfo::sign(const Store & store, const Signer & signer)
4040
sigs.insert(signer.signDetached(fingerprint(store)));
4141
}
4242

43+
void ValidPathInfo::sign(const Store & store, const std::vector<std::unique_ptr<Signer>> & signers)
44+
{
45+
auto fingerprint = this->fingerprint(store);
46+
for (auto & signer: signers) {
47+
sigs.insert(signer->signDetached(fingerprint));
48+
}
49+
}
50+
4351
std::optional<ContentAddressWithReferences> ValidPathInfo::contentAddressWithReferences() const
4452
{
4553
if (! ca)

0 commit comments

Comments
 (0)