-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare 3rd-party attestations (#73)
- Loading branch information
Showing
5 changed files
with
98 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.bzzt.reproduciblebuilds | ||
|
||
import java.net.URI | ||
|
||
case class VerificationResult( | ||
uri: URI, | ||
ourSums: Map[String, Checksum], | ||
remoteSums: Map[String, Checksum], | ||
) { | ||
def verdicts: Seq[(String, String)] = | ||
ourSums.map { | ||
case (key, value) => (key, verdict(key, value)) | ||
}.toSeq ++ | ||
ourSums.keySet.diff(remoteSums.keySet).map { missingInTheirs => (missingInTheirs, "Missing in their checksums but present in ours") } ++ | ||
remoteSums.keySet.diff(ourSums.keySet).map { missingInOurs => (missingInOurs, "Missing in our checksums but present in theirs") } | ||
|
||
def verdict(filename: String, ourSum: Checksum): String = remoteSums.get(filename) match { | ||
case None => "Not found in remote attestation" | ||
case Some(checksum) => | ||
if (checksum == ourSum) "Match" | ||
else s"Mismatch: our ${ourSum.hexChecksum} did not match their ${checksum.hexChecksum}" | ||
} | ||
|
||
def ok = ourSums == remoteSums | ||
} | ||
|
||
object VerificationResult { | ||
def apply(uri: URI, ourSums: Seq[Checksum], remoteSums: Seq[Checksum]) = { | ||
new VerificationResult( | ||
uri, | ||
groupByUnique(ourSums)(_.filename), | ||
groupByUnique(remoteSums)(_.filename), | ||
) | ||
} | ||
|
||
private def groupByUnique[K, V](elements: Seq[V])(f: V => K): Map[K, V] = | ||
elements.groupBy(f).map { | ||
case (key, Seq(value)) => (key, value) | ||
case (key, values) => throw new IllegalArgumentException(s"Found ${values.size} elements for key $key") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters