}
`}
-redef class NativeString
- private fun sha1_intern(len: Int): NativeString `{
+redef class CString
+ private fun sha1_intern(len: Int): CString `{
sha1nfo s;
sha1_init(&s);
`}
end
-redef class String
+redef class Text
# Computes the SHA1 of the receiver
#
- # Returns a digest of 20 bytes as a NativeString,
+ # Returns a digest of 20 bytes as a CString,
# note that all the characters are not necessarily ASCII.
# If you want the hex string version of the digest, use
# sha1_hexdigest.
# import base64
# assert "The quick brown fox jumps over the lazy dog".sha1 == [0x2Fu8, 0xD4u8, 0xE1u8, 0xC6u8, 0x7Au8, 0x2Du8, 0x28u8, 0xFCu8, 0xEDu8, 0x84u8, 0x9Eu8, 0xE1u8, 0xBBu8, 0x76u8, 0xE7u8, 0x39u8, 0x1Bu8, 0x93u8, 0xEBu8, 0x12u8]
fun sha1: Bytes do
- return new Bytes(to_cstring.sha1_intern(bytelen), 20, 20)
+ return new Bytes(to_cstring.sha1_intern(byte_length), 20, 20)
end
# Computes the SHA1 of the receiver.
#
# assert "The quick brown fox jumps over the lazy dog".sha1_hexdigest == "2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12"
fun sha1_hexdigest: String do return sha1.hexdigest
+
+ # Is `self` a SHA-1 hexdigest?
+ #
+ #~~~nit
+ # assert "2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12".is_sha1_digest
+ # assert not "Not a digest".is_sha1_digest
+ # assert not "2FD4E1C67A2D28FCED849EE1B76E7391B93EB12".is_sha1_digest
+ # assert not "2FD4E1C67A2D28FCED849EE1UB76E7391B93EB12".is_sha1_digest
+ #~~~
+ fun is_sha1_digest: Bool do return length == 40 and is_hex
end