-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Checksum class for plumbing HTTP downloader content checksums.
This is extracted from #7208 ("Support subresource integrity format for `download()` checksums.") I'm trying to revive that PR and rebase to master, but the replacement of `String sha256` through the HTTP downloader code is causing a lot of Git conflicts. I expect that portion of the change to require less discussion than the proposed content integrity changes, so I'm moving it to a separate PR to simplify review. @dslomov or @aehlig, could one of you take a look? Once this is merged, I will rebase PR 7208 onto it. Closes #8714. PiperOrigin-RevId: 256188026
- Loading branch information
1 parent
2260b97
commit 62fa89d
Showing
11 changed files
with
233 additions
and
134 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java
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,50 @@ | ||
// Copyright 2019 The Bazel Authors. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.devtools.build.lib.bazel.repository.downloader; | ||
|
||
import com.google.common.hash.HashCode; | ||
import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.KeyType; | ||
|
||
/** The content checksum for an HTTP download, which knows its own type. */ | ||
public class Checksum { | ||
private final KeyType keyType; | ||
private final HashCode hashCode; | ||
|
||
private Checksum(KeyType keyType, HashCode hashCode) { | ||
this.keyType = keyType; | ||
this.hashCode = hashCode; | ||
} | ||
|
||
/** Constructs a new Checksum for a given key type and hash, in hex format. */ | ||
public static Checksum fromString(KeyType keyType, String hash) { | ||
if (!keyType.isValid(hash)) { | ||
throw new IllegalArgumentException("Invalid " + keyType + " checksum '" + hash + "'"); | ||
} | ||
return new Checksum(keyType, HashCode.fromString(hash)); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return hashCode.toString(); | ||
} | ||
|
||
public HashCode getHashCode() { | ||
return hashCode; | ||
} | ||
|
||
public KeyType getKeyType() { | ||
return keyType; | ||
} | ||
} |
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
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
Oops, something went wrong.