diff --git a/log/log.go b/log/log.go index 2a581eb4991..ef3e44cb3d7 100644 --- a/log/log.go +++ b/log/log.go @@ -160,11 +160,9 @@ type stdoutWriter struct { isatty bool } -// NewLineChecksum computes a CRC32 over the log line, which can be checked by +// LogLineChecksum computes a CRC32 over the log line, which can be checked by // log-validator to ensure no unexpected log corruption has occurred. -// It is currently only accepted for Validation, and will be switched in for -// LogLineChecksum in an upcoming release. -func NewLineChecksum(line string) string { +func LogLineChecksum(line string) string { crc := crc32.ChecksumIEEE([]byte(line)) buf := make([]byte, crc32.Size) // Error is unreachable because we provide a supported type and buffer size @@ -172,8 +170,8 @@ func NewLineChecksum(line string) string { return base64.RawURLEncoding.EncodeToString(buf) } -// LogLineChecksum is the current checksum algorithm, emitted in every log line. -func LogLineChecksum(line string) string { +// OldLineChecksum was previously used, and is still accepted for validation. +func OldLineChecksum(line string) string { crc := crc32.ChecksumIEEE([]byte(line)) // Using the hash.Hash32 doesn't make this any easier // as it also returns a uint32 rather than []byte diff --git a/log/log_test.go b/log/log_test.go index 8e7d0486f41..f7dea3f5789 100644 --- a/log/log_test.go +++ b/log/log_test.go @@ -102,8 +102,8 @@ func TestStdoutLogger(t *testing.T) { logger.Warning("Warning log") logger.Info("Info log") - test.AssertEquals(t, stdout.String(), "1970-01-01 prefix 6 log.test pcbo7wk Info log\n") - test.AssertEquals(t, stderr.String(), "1970-01-01 prefix 3 log.test 46_ghQg [AUDIT] Error Audit\n1970-01-01 prefix 4 log.test 97r2xAw Warning log\n") + test.AssertEquals(t, stdout.String(), "1970-01-01 prefix 6 log.test JSP6nQ Info log\n") + test.AssertEquals(t, stderr.String(), "1970-01-01 prefix 3 log.test 4xe4gA [AUDIT] Error Audit\n1970-01-01 prefix 4 log.test d52dyA Warning log\n") } func TestSyslogMethods(t *testing.T) { @@ -352,14 +352,14 @@ func TestLogLineChecksum(t *testing.T) { expected string }{ { - name: "NewLineChecksum with Hello, World!", - function: NewLineChecksum, + name: "LogLineChecksum with Hello, World!", + function: LogLineChecksum, input: "Hello, World!", expected: "0MNK7A", }, { - name: "LogLineChecksum with Info log", - function: LogLineChecksum, + name: "OldLineChecksum with Info log", + function: OldLineChecksum, input: "Info log", expected: "pcbo7wk", }, diff --git a/log/validator/validator.go b/log/validator/validator.go index c21a8a5d95a..8a931a5b212 100644 --- a/log/validator/validator.go +++ b/log/validator/validator.go @@ -208,9 +208,9 @@ func lineValid(text string) error { // TODO(#8414): Accept both the old and new checksum format, distinguished by length var computedChecksum string if len(checksum) == 6 { - computedChecksum = log.NewLineChecksum(line) - } else { computedChecksum = log.LogLineChecksum(line) + } else { + computedChecksum = log.OldLineChecksum(line) } if checksum != computedChecksum { return fmt.Errorf("%s invalid checksum (expected %q, got %q)", errorPrefix, computedChecksum, checksum)