Bredbandskollen CLI  1.2
Asynchronous network task engine
sha1.h
1 // Copyright (c) 2017 IIS (The Internet Foundation in Sweden)
2 // Based on public domain code.
3 // Modified by Göran Andersson <goran@init.se>
4 
5 #pragma once
6 
7 #include <iostream>
8 #include <string>
9 #include <cstdint>
10 
11 void base64_encode(const unsigned char *src, size_t len, char *destination);
12 
13 class SHA1 {
14 public:
15  // You provide a buffer, at least 27 bytes large.
16  SHA1(char *buf);
17 
18  // Result (base64 encoded) will be stored in buf, no nul termination.
19  void update(const char *key);
20 
21 private:
22  static bool is_big_endian;
23  char *the_res;
24 
25  static const uint32_t DIGEST_INTS = 5; // number of 32bit integers per SHA1 digest
26  static const unsigned int BLOCK_INTS = 16; // number of 32bit integers per SHA1 block
27  static const unsigned int BLOCK_BYTES = BLOCK_INTS * 4;
28 
29  uint32_t digest[DIGEST_INTS];
30  uint64_t transforms;
31 
32  void transform(uint32_t block[BLOCK_BYTES]);
33 
34  static void buffer_to_block(const std::string &buffer, uint32_t block[BLOCK_BYTES]);
35  static void read(std::istream &is, std::string &s, int max);
36 };
Definition: sha1.h:13