@@ -119,19 +119,22 @@ private Blake3(final int[] key, final int flags) {
119119
120120 /**
121121 * Resets this instance back to its initial state when it was first constructed.
122+ * @return this
122123 */
123- public void reset () {
124+ public Blake3 reset () {
124125 engineState .reset ();
126+ return this ;
125127 }
126128
127129 /**
128130 * Updates this hash state using the provided bytes.
129131 *
130132 * @param in source array to update data from
133+ * @return this
131134 * @throws NullPointerException if in is null
132135 */
133- public void update (final byte [] in ) {
134- update (in , 0 , in .length );
136+ public Blake3 update (final byte [] in ) {
137+ return update (in , 0 , in .length );
135138 }
136139
137140 /**
@@ -140,24 +143,27 @@ public void update(final byte[] in) {
140143 * @param in source array to update data from
141144 * @param offset where in the array to begin reading bytes
142145 * @param length number of bytes to update
146+ * @return this
143147 * @throws NullPointerException if in is null
144148 * @throws IndexOutOfBoundsException if offset or length are negative or if offset + length is greater than the
145149 * length of the provided array
146150 */
147- public void update (final byte [] in , final int offset , final int length ) {
151+ public Blake3 update (final byte [] in , final int offset , final int length ) {
148152 checkBufferArgs (in , offset , length );
149153 engineState .inputData (in , offset , length );
154+ return this ;
150155 }
151156
152157 /**
153158 * Finalizes hash output data that depends on the sequence of updated bytes preceding this invocation and any
154159 * previously finalized bytes. Note that this can finalize up to 2<sup>64</sup> bytes per instance.
155160 *
156161 * @param out destination array to finalize bytes into
162+ * @return this
157163 * @throws NullPointerException if out is null
158164 */
159- public void doFinalize (final byte [] out ) {
160- doFinalize (out , 0 , out .length );
165+ public Blake3 doFinalize (final byte [] out ) {
166+ return doFinalize (out , 0 , out .length );
161167 }
162168
163169 /**
@@ -167,13 +173,15 @@ public void doFinalize(final byte[] out) {
167173 * @param out destination array to finalize bytes into
168174 * @param offset where in the array to begin writing bytes to
169175 * @param length number of bytes to finalize
176+ * @return this
170177 * @throws NullPointerException if out is null
171178 * @throws IndexOutOfBoundsException if offset or length are negative or if offset + length is greater than the
172179 * length of the provided array
173180 */
174- public void doFinalize (final byte [] out , final int offset , final int length ) {
181+ public Blake3 doFinalize (final byte [] out , final int offset , final int length ) {
175182 checkBufferArgs (out , offset , length );
176183 engineState .outputHash (out , offset , length );
184+ return this ;
177185 }
178186
179187 /**
@@ -244,9 +252,7 @@ public static Blake3 initKeyDerivationFunction(final byte[] kdfContext) {
244252 * @throws NullPointerException if data is null
245253 */
246254 public static byte [] hash (final byte [] data ) {
247- final Blake3 blake3 = Blake3 .initHash ();
248- blake3 .update (data );
249- return blake3 .doFinalize (OUT_LEN );
255+ return Blake3 .initHash ().update (data ).doFinalize (OUT_LEN );
250256 }
251257
252258 /**
@@ -258,9 +264,7 @@ public static byte[] hash(final byte[] data) {
258264 * @throws NullPointerException if key or data are null
259265 */
260266 public static byte [] keyedHash (final byte [] key , final byte [] data ) {
261- final Blake3 blake3 = Blake3 .initKeyedHash (key );
262- blake3 .update (data );
263- return blake3 .doFinalize (OUT_LEN );
267+ return Blake3 .initKeyedHash (key ).update (data ).doFinalize (OUT_LEN );
264268 }
265269
266270 private static void checkBufferArgs (final byte [] buffer , final int offset , final int length ) {
0 commit comments