IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IKVM.Runtime.StubGen.SHA1HashWriter Struct Reference

Provides methods to write basic building blocks to an incremental hash. More...

Inheritance diagram for IKVM.Runtime.StubGen.SHA1HashWriter:

Public Member Functions

 SHA1HashWriter ()
 Initializes a new instance.
 
void WriteUInt16 (ushort s)
 
void WriteUInt32 (uint u)
 
void WriteInt64 (long l)
 
void WriteFloat (float f)
 
void WriteDouble (double d)
 
void WriteByte (byte b)
 
void WriteBytes (byte[] data)
 
void WriteUtf8 (string str)
 
byte[] Finalize ()
 Finalizes the SHA1.
 
void Dispose ()
 Disposes of the instance.
 

Public Attributes

readonly IncrementalHash hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA1)
 

Detailed Description

Provides methods to write basic building blocks to an incremental hash.

The Framework version of this code writes to a temporary heap array.

Definition at line 15 of file SHA1HashWriter.cs.

Constructor & Destructor Documentation

◆ SHA1HashWriter()

IKVM.Runtime.StubGen.SHA1HashWriter.SHA1HashWriter ( )

Initializes a new instance.

Definition at line 26 of file SHA1HashWriter.cs.

27 {
28
29 }

Member Function Documentation

◆ Dispose()

void IKVM.Runtime.StubGen.SHA1HashWriter.Dispose ( )

Disposes of the instance.

Definition at line 149 of file SHA1HashWriter.cs.

150 {
151#if NETFRAMEWORK
152 ArrayPool<byte>.Shared.Return(temp);
153#endif
154 }

◆ Finalize()

byte[] IKVM.Runtime.StubGen.SHA1HashWriter.Finalize ( )

Finalizes the SHA1.

Returns

Definition at line 141 of file SHA1HashWriter.cs.

142 {
143 return hash.GetHashAndReset();
144 }
readonly IncrementalHash hash

◆ WriteByte()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteByte ( byte b)

Definition at line 77 of file SHA1HashWriter.cs.

78 {
79#if NETFRAMEWORK
80 temp[0] = b;
81 hash.AppendData(temp, 0, 1);
82#else
83 var span = (Span<byte>)stackalloc byte[1];
84 span[0] = b;
85 hash.AppendData(span);
86#endif
87 }

◆ WriteBytes()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteBytes ( byte[] data)

Definition at line 89 of file SHA1HashWriter.cs.

90 {
91 hash.AppendData(data);
92 }

◆ WriteDouble()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteDouble ( double d)

Definition at line 72 of file SHA1HashWriter.cs.

73 {
74 WriteInt64(BitConverter.ToInt64(BitConverter.GetBytes(d), 0));
75 }

◆ WriteFloat()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteFloat ( float f)

Definition at line 67 of file SHA1HashWriter.cs.

68 {
69 WriteUInt32(BitConverter.ToUInt32(BitConverter.GetBytes(f), 0));
70 }

◆ WriteInt64()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteInt64 ( long l)

Definition at line 55 of file SHA1HashWriter.cs.

56 {
57#if NETFRAMEWORK
58 BinaryPrimitives.WriteInt64BigEndian(temp, l);
59 hash.AppendData(temp, 0, 8);
60#else
61 var span = (Span<byte>)stackalloc byte[8];
62 BinaryPrimitives.WriteInt64BigEndian(span, l);
63 hash.AppendData(span);
64#endif
65 }

◆ WriteUInt16()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteUInt16 ( ushort s)

Definition at line 31 of file SHA1HashWriter.cs.

32 {
33#if NETFRAMEWORK
34 BinaryPrimitives.WriteUInt16BigEndian(temp, s);
35 hash.AppendData(temp, 0, 2);
36#else
37 var buf = (Span<byte>)stackalloc byte[2];
38 BinaryPrimitives.WriteUInt16BigEndian(buf, s);
39 hash.AppendData(buf);
40#endif
41 }

◆ WriteUInt32()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteUInt32 ( uint u)

Definition at line 43 of file SHA1HashWriter.cs.

44 {
45#if NETFRAMEWORK
46 BinaryPrimitives.WriteUInt32BigEndian(temp, u);
47 hash.AppendData(temp, 0, 4);
48#else
49 var span = (Span<byte>)stackalloc byte[4];
50 BinaryPrimitives.WriteUInt32BigEndian(span, u);
51 hash.AppendData(span);
52#endif
53 }

◆ WriteUtf8()

void IKVM.Runtime.StubGen.SHA1HashWriter.WriteUtf8 ( string str)

Definition at line 94 of file SHA1HashWriter.cs.

95 {
96 var buf = ArrayPool<byte>.Shared.Rent(str.Length * 3 + 1);
97
98 try
99 {
100 int j = 0;
101 for (int i = 0, e = str.Length; i < e; i++)
102 {
103 char ch = str[i];
104 if ((ch != 0) && (ch <= 0x7f))
105 {
106 buf[j++] = (byte)ch;
107 }
108 else if (ch <= 0x7FF)
109 {
110 /* 11 bits or less. */
111 var high_five = (byte)(ch >> 6);
112 var low_six = (byte)(ch & 0x3F);
113 buf[j++] = (byte)(high_five | 0xC0); /* 110xxxxx */
114 buf[j++] = (byte)(low_six | 0x80); /* 10xxxxxx */
115 }
116 else
117 {
118 /* possibly full 16 bits. */
119 var high_four = (byte)(ch >> 12);
120 var mid_six = (byte)((ch >> 6) & 0x3F);
121 var low_six = (byte)(ch & 0x3f);
122 buf[j++] = (byte)(high_four | 0xE0); /* 1110xxxx */
123 buf[j++] = (byte)(mid_six | 0x80); /* 10xxxxxx */
124 buf[j++] = (byte)(low_six | 0x80); /* 10xxxxxx*/
125 }
126 }
127
128 WriteUInt16((ushort)j);
129 hash.AppendData(buf, 0, j);
130 }
131 finally
132 {
133 ArrayPool<byte>.Shared.Return(buf);
134 }
135 }

Member Data Documentation

◆ hash

readonly IncrementalHash IKVM.Runtime.StubGen.SHA1HashWriter.hash = IncrementalHash.CreateHash(HashAlgorithmName.SHA1)

Definition at line 18 of file SHA1HashWriter.cs.


The documentation for this struct was generated from the following file: