forked from harrisonpartch/spasim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CryptoHashes.Mod
executable file
·60 lines (48 loc) · 1.38 KB
/
CryptoHashes.Mod
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
MODULE CryptoHashes; (** AUTHOR "G.F."; PURPOSE "Empty Hash"; *)
TYPE
Hash* = OBJECT
VAR
name-: ARRAY 64 OF CHAR;
size-: LONGINT;
initialized*: BOOLEAN;
PROCEDURE &Init*;
BEGIN
initialized := FALSE
END Init;
PROCEDURE Initialize*;
BEGIN
HALT(301) (* force overwriting *)
END Initialize;
(** this method is invoked by subclasses *)
PROCEDURE SetNameAndSize*( CONST name: ARRAY OF CHAR; size: LONGINT );
BEGIN
COPY( name, SELF.name );
SELF.size := size
END SetNameAndSize;
(** data: value to be hashed; when Update is invoked several times before GetHash or Initialize
is invoked, the concatenation of all data-parameters is hashed *)
PROCEDURE Update*( CONST data: ARRAY OF CHAR; ofs, len: LONGINT );
BEGIN
HALT(301) (* force overwriting *)
END Update;
(** get the hashvalue of length SELF.size *)
PROCEDURE GetHash*( VAR buffer: ARRAY OF CHAR; position: LONGINT );
BEGIN
HALT(301) (* force overwriting *)
END GetHash;
END Hash;
HashFactory = PROCEDURE( ): Hash;
(** get a new hash from module 'modname' *)
PROCEDURE NewHash*( CONST modname: ARRAY OF CHAR ): Hash;
VAR hash : Hash; factory : HashFactory;
BEGIN
ASSERT( LEN( modname ) < 57 );
hash := NIL;
GETPROCEDURE( modname, "NewHash", factory );
IF factory # NIL THEN
hash := factory();
END;
RETURN hash;
END NewHash;
END CryptoHashes.
System.Free CryptoHashes~