Skip to content

Commit

Permalink
Merge pull request #1982 from ivan444/rm_sha
Browse files Browse the repository at this point in the history
Remove boringssl dependency. Replace sha256 with absl::Hash.
  • Loading branch information
hzeller authored Jul 26, 2023
2 parents fa07295 + 5f238a6 commit a1cd07b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
9 changes: 0 additions & 9 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,3 @@ maybe(
"https://zlib.net/fossils/zlib-1.2.13.tar.gz",
],
)

# Only needed for sha256; Version taken from branch with bazel rules
# https://github.com/google/boringssl/tree/master-with-bazel
http_archive(
name = "com_google_boringssl",
sha256 = "8b28b030652d1b5e0f8de306e8bdc1b67f7164c2ec889056a0c13e78ba615a34",
strip_prefix = "boringssl-342e805bc1f5dfdd650e3f031686d6c939b095d9",
urls = ["https://github.com/google/boringssl/archive/342e805bc1f5dfdd650e3f031686d6c939b095d9.zip"],
)
2 changes: 1 addition & 1 deletion verilog/tools/kythe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ cc_library(
"//common/util:file-util",
"//common/util:simple-zip",
"//third_party/proto/kythe:analysis_cc_proto",
"@com_google_absl//absl/hash",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_boringssl//:crypto",
],
)

Expand Down
14 changes: 5 additions & 9 deletions verilog/tools/kythe/kzip_creator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#include <string>
#include <vector>

#include "absl/hash/hash.h"
#include "absl/status/status.h"
#include "absl/strings/escaping.h"
#include "absl/strings/string_view.h"
#include "common/util/file_util.h"
#include "common/util/simple_zip.h"
#include "openssl/sha.h"
#include "third_party/proto/kythe/analysis.pb.h"

namespace verilog {
Expand All @@ -34,12 +34,8 @@ namespace {
constexpr absl::string_view kProtoUnitRoot = "root/pbunits/";
constexpr absl::string_view kFileRoot = "root/files/";

std::string SHA256Digest(absl::string_view content) {
std::array<unsigned char, SHA256_DIGEST_LENGTH> buf;
::SHA256(reinterpret_cast<const unsigned char *>(content.data()),
content.size(), buf.data());
return absl::BytesToHexString(absl::string_view(
reinterpret_cast<const char *>(buf.data()), buf.size()));
std::string Digest(absl::string_view content) {
return absl::StrCat(absl::HashOf(content));
}

constexpr int kKZipCompressionLevel = 9;
Expand All @@ -58,7 +54,7 @@ KzipCreator::KzipCreator(absl::string_view output_path)

std::string KzipCreator::AddSourceFile(absl::string_view path,
absl::string_view content) {
std::string digest = SHA256Digest(content);
std::string digest = Digest(content);
const std::string archive_path = verible::file::JoinPath(kFileRoot, digest);
archive_.AddFile(archive_path, verible::zip::MemoryByteSource(content));
return digest;
Expand All @@ -70,7 +66,7 @@ absl::Status KzipCreator::AddCompilationUnit(
if (!unit.SerializeToString(&content)) {
return absl::InternalError("Failed to serialize the compilation unit");
}
const std::string digest = SHA256Digest(content);
const std::string digest = Digest(content);
const std::string archive_path =
verible::file::JoinPath(kProtoUnitRoot, digest);
archive_.AddFile(archive_path, verible::zip::MemoryByteSource(content));
Expand Down
2 changes: 1 addition & 1 deletion verilog/tools/kythe/kzip_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class KzipCreator final {
// Initializes the archive. Crashes if initialization fails.
explicit KzipCreator(absl::string_view output_path);

// Adds source code file to the Kzip. Returns its SHA digest.
// Adds source code file to the Kzip. Returns its digest.
std::string AddSourceFile(absl::string_view path, absl::string_view content);

// Adds compilation unit to the Kzip.
Expand Down

0 comments on commit a1cd07b

Please sign in to comment.