Skip to content

Add tests to crypto package

Christopher Schinnerl requested to merge VoidingWarranties:crypto-tests into master

Created by: VoidingWarranties

Brings tests coverage for the crypto package from 74.2% to 91.6%. No mocking was used in the tests added. The remaining tests necessary to bring the package up to 100% coverage will require mocking.

NOTE: TestPartialLastLeafReadSegments will fail (as it should) until PR #880 is merged.

Tests added:

  • discard_test.go
    • TestUnitSecureWipe
    • TestUnitSecureWipeEdgeCases
  • encrypt_test.go
    • TestUnitCiphertextUnmarshalJSON
    • TestCiphertextMarshalling
  • hash_test.go
    • TestUnitHashMarshalJSON
    • TestUnitHashUnmarshalJSON
  • merkle_test.go
    • TestReadSegments
    • TestPartialLastLeafReadSegments
  • rand_test.go
    • TestRandIntnPanics

Besides tests, Hash.String and Hash.UnmarshalJSON were modified to encode / decode hashes to / from strings using hex.EncodeToString and hex.DecodeString, respectively. The previous implementation used fmt.Printf and fmt.Scanf. Unlike the fmt package, the hex package does not use reflection. The intent of the code is also more clear with the hex package.

Merge request reports