compiler: add abstraction layer for sha1 checksums.
Add new interface for the front end code to use when computing SHA1
checksums; the intent is to allow the different implementation in
different back ends.
No change in functionality for gccgo; this is an enabling change to
permit the front end to be used with other back ends (e.g. LLVM).
Change-Id: Ia9afcccc1fe4a1546cd2cdbde2e6fc79a6cea0bf
Reviewed-on: https://go-review.googlesource.com/28833
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/export.cc b/go/export.cc
index e9040ef..bec4c7f 100644
--- a/go/export.cc
+++ b/go/export.cc
@@ -6,8 +6,7 @@
#include "go-system.h"
-#include "sha1.h"
-
+#include "go-sha1.h"
#include "go-c.h"
#include "gogo.h"
@@ -40,6 +39,7 @@
Export::Export(Stream* stream)
: stream_(stream), type_refs_(), type_index_(1), packages_()
{
+ go_assert(Export::checksum_len == Go_sha1_helper::checksum_len);
}
// A functor to sort Named_object pointers by name.
@@ -686,9 +686,8 @@
Export::Stream::Stream()
{
- this->checksum_ = new sha1_ctx;
- memset(this->checksum_, 0, sizeof(sha1_ctx));
- sha1_init_ctx(this->checksum_);
+ this->sha1_helper_ = go_create_sha1_helper();
+ go_assert(this->sha1_helper_ != NULL);
}
Export::Stream::~Stream()
@@ -701,7 +700,7 @@
void
Export::Stream::write_and_sum_bytes(const char* bytes, size_t length)
{
- sha1_process_bytes(bytes, length, this->checksum_);
+ this->sha1_helper_->process_bytes(bytes, length);
this->do_write(bytes, length);
}
@@ -710,14 +709,9 @@
std::string
Export::Stream::checksum()
{
- // Use a union to provide the required alignment.
- union
- {
- char checksum[Export::checksum_len];
- long align;
- } u;
- sha1_finish_ctx(this->checksum_, u.checksum);
- return std::string(u.checksum, Export::checksum_len);
+ std::string rval = this->sha1_helper_->finish();
+ delete this->sha1_helper_;
+ return rval;
}
// Write the checksum string to the export data.