| 12345678910111213141516171819202122232425262728293031323334353637 |
- using Invercargill;
- namespace Pprf.Util {
- public static uint8[] string_checksum(string str) {
- return data_checksum(str.data);
- }
- public static uint8[] data_checksum(uint8[] data) {
- var checksum_calculator = new Checksum(ChecksumType.SHA512);
- checksum_calculator.update(data, data.length);
- var checksum = new uint8[ChecksumType.SHA512.get_length()];
- size_t chk_len = checksum.length;
- checksum_calculator.get_digest(checksum, ref chk_len);
- checksum.length = (int)chk_len;
- return checksum;
- }
- public static uint8[] file_checksum(File file) throws Error {
- var buffer = new uint8[10240];
- var checksum = new Checksum(ChecksumType.SHA512);
- var stream = file.read();
- while(true) {
- var read = stream.read(buffer);
- if(read == 0) {
- break;
- }
- checksum.update(buffer, read);
- }
- size_t dig_len = 64;
- var digest = new uint8[64];
- checksum.get_digest(digest, ref dig_len);
- digest.length = (int)dig_len;
- return digest;
- }
- }
|