├── .gitignore ├── test ├── package-set.dhall ├── vessel.dhall ├── Makefile └── Test.mo ├── vessel.dhall ├── dfx.json ├── package-set.dhall ├── run.sh ├── README.md ├── Makefile ├── NOTICE ├── .github └── workflows │ ├── ci.yml │ └── release.yml ├── src └── SHA256.mo └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .vessel 2 | *.wasm 3 | docs/ 4 | -------------------------------------------------------------------------------- /test/package-set.dhall: -------------------------------------------------------------------------------- 1 | ../package-set.dhall 2 | -------------------------------------------------------------------------------- /vessel.dhall: -------------------------------------------------------------------------------- 1 | { dependencies = [ "base" ], compiler = Some "0.5.14" } 2 | -------------------------------------------------------------------------------- /dfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "canisters": { 3 | "test": { 4 | "main": "test/Main.mo" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/vessel.dhall: -------------------------------------------------------------------------------- 1 | let mainVessel = ../vessel.dhall 2 | 3 | in mainVessel 4 | with dependencies = mainVessel.dependencies # [ "matchers" ] 5 | -------------------------------------------------------------------------------- /test/Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | $(shell vessel bin)/moc $(shell vessel sources) -wasi-system-api -o Test.wasm Test.mo && wasmtime Test.wasm 3 | rm -f Test.wasm 4 | -------------------------------------------------------------------------------- /package-set.dhall: -------------------------------------------------------------------------------- 1 | let upstream = 2 | https://github.com/dfinity/vessel-package-set/releases/download/mo-0.5.14-20210409/package-set.dhall sha256:8ebfd1c83165bbbc3e961b0deb7f4dad6e55935c93a6e580b7b884d5661c8cbe 3 | 4 | in upstream 5 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | echo PATH = $PATH 2 | echo vessel @ `which vessel` 3 | 4 | echo 5 | echo == Build. 6 | echo 7 | 8 | dfx start --background 9 | dfx canister create --all 10 | dfx build 11 | 12 | echo 13 | echo == Test. 14 | echo 15 | 16 | dfx canister install --all --mode=reinstall 17 | dfx canister call test run '()' 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## The SHA Package 2 | 3 | [![Build Status](https://github.com/enzoh/motoko-sha/workflows/build/badge.svg)](https://github.com/enzoh/motoko-sha/actions?query=workflow%3Abuild) 4 | 5 | This package implements secure hash algorithms for the Motoko programming language. 6 | 7 | ### Usage 8 | 9 | Calculate a SHA256 hash. 10 | ```motoko 11 | public func sha256(data : [Nat8]) : [Nat8] 12 | ``` 13 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: check docs test 2 | 3 | check: 4 | find src -type f -name '*.mo' -print0 | xargs -0 $(shell vessel bin)/moc $(shell vessel sources) --check 5 | 6 | all: check-strict docs test 7 | 8 | check-strict: 9 | find src -type f -name '*.mo' -print0 | xargs -0 $(shell vessel bin)/moc $(shell vessel sources) -Werror --check 10 | docs: 11 | $(shell vessel bin)/mo-doc 12 | test: 13 | make -C test 14 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Enzo Haussecker 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: "install wasmtime" 11 | run: | 12 | mkdir /home/runner/bin 13 | echo "/home/runner/bin" >> $GITHUB_PATH 14 | wget https://github.com/bytecodealliance/wasmtime/releases/download/v0.18.0/wasmtime-v0.18.0-x86_64-linux.tar.xz 15 | tar xf wasmtime-v0.18.0-x86_64-linux.tar.xz 16 | cp wasmtime-v0.18.0-x86_64-linux/wasmtime /home/runner/bin/wasmtime 17 | - name: "install vessel" 18 | run: | 19 | wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/v0.6.0/vessel-linux64 20 | chmod +x /home/runner/bin/vessel 21 | - name: "check" 22 | run: make check-strict 23 | - name: "test" 24 | run: make test 25 | - name: "docs" 26 | run: make docs 27 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | # until we do releases, deploy docs with every commit to main 4 | on: 5 | push: 6 | branch: 7 | - main 8 | # tags: 9 | # - '*' 10 | 11 | jobs: 12 | generate-docs: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v1 16 | - name: "install vessel" 17 | run: | 18 | mkdir /home/runner/bin 19 | echo "/home/runner/bin" >> $GITHUB_PATH 20 | wget --output-document /home/runner/bin/vessel https://github.com/dfinity/vessel/releases/download/v0.6.0/vessel-linux64 21 | chmod +x /home/runner/bin/vessel 22 | - name: "docs" 23 | run: make docs 24 | - name: Upload docs 25 | uses: JamesIves/github-pages-deploy-action@releases/v3 26 | with: 27 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 28 | BRANCH: gh-pages # The branch the action should deploy to. 29 | FOLDER: docs/ # The folder the action should deploy. 30 | -------------------------------------------------------------------------------- /src/SHA256.mo: -------------------------------------------------------------------------------- 1 | /** 2 | * Module : SHA256.mo 3 | * Description : Cryptographic hash function. 4 | * Copyright : 2020 DFINITY Stiftung 5 | * License : Apache 2.0 with LLVM Exception 6 | * Maintainer : Enzo Haussecker 7 | * Stability : Stable 8 | */ 9 | 10 | import Array "mo:base/Array"; 11 | import Iter "mo:base/Iter"; 12 | import Nat "mo:base/Nat"; 13 | import Nat8 "mo:base/Nat8"; 14 | import Nat32 "mo:base/Nat32"; 15 | import Nat64 "mo:base/Nat64"; 16 | 17 | module { 18 | 19 | private let K : [Nat32] = [ 20 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 21 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 22 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 23 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 24 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 25 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 26 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 27 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 28 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 29 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 30 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 31 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 32 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 33 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 34 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 35 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, 36 | ]; 37 | 38 | private let S : [Nat32] = [ 39 | 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 40 | 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, 41 | ]; 42 | 43 | // Calculate a SHA256 hash. 44 | public func sha256(data : [Nat8]) : [Nat8] { 45 | let digest = Digest(); 46 | digest.write(data); 47 | return digest.sum(); 48 | }; 49 | 50 | public class Digest() { 51 | 52 | private let s = Array.thaw(S); 53 | 54 | private let x = Array.init(64, 0); 55 | 56 | private var nx = 0; 57 | 58 | private var len : Nat64 = 0; 59 | 60 | public func reset() { 61 | for (i in Iter.range(0, 7)) { 62 | s[i] := S[i]; 63 | }; 64 | nx := 0; 65 | len := 0; 66 | }; 67 | 68 | public func write(data : [Nat8]) { 69 | var p = data; 70 | len +%= Nat64.fromIntWrap(p.size()); 71 | if (nx > 0) { 72 | let n = Nat.min(p.size(), 64 - nx); 73 | for (i in Iter.range(0, n - 1)) { 74 | x[nx + i] := p[i]; 75 | }; 76 | nx += n; 77 | if (nx == 64) { 78 | let buf = Array.freeze(x); 79 | block(buf); 80 | nx := 0; 81 | }; 82 | p := Array.tabulate(p.size() - n, func (i) { 83 | return p[n + i]; 84 | }); 85 | }; 86 | if (p.size() >= 64) { 87 | let n = Nat64.toNat(Nat64.fromIntWrap(p.size()) & (^ 63)); 88 | let buf = Array.tabulate(n, func (i) { 89 | return p[i]; 90 | }); 91 | block(buf); 92 | p := Array.tabulate(p.size() - n, func (i) { 93 | return p[n + i]; 94 | }); 95 | }; 96 | if (p.size() > 0) { 97 | for (i in Iter.range(0, p.size() - 1)) { 98 | x[i] := p[i]; 99 | }; 100 | nx := p.size(); 101 | }; 102 | }; 103 | 104 | public func sum() : [Nat8] { 105 | var m = 0; 106 | var n = len; 107 | var t = Nat64.toNat(n) % 64; 108 | var buf : [var Nat8] = [var]; 109 | if (56 > t) { 110 | m := 56 - t; 111 | } else { 112 | m := 120 - t; 113 | }; 114 | n := n << 3; 115 | buf := Array.init(m, 0); 116 | if (m > 0) { 117 | buf[0] := 0x80; 118 | }; 119 | write(Array.freeze(buf)); 120 | buf := Array.init(8, 0); 121 | for (i in Iter.range(0, 7)) { 122 | let j : Nat64 = 56 -% 8 *% Nat64.fromIntWrap(i); 123 | buf[i] := Nat8.fromIntWrap(Nat64.toNat(n >> j)); 124 | }; 125 | write(Array.freeze(buf)); 126 | let hash = Array.init(32, 0); 127 | for (i in Iter.range(0, 7)) { 128 | for (j in Iter.range(0, 3)) { 129 | let k : Nat32 = 24 -% 8 *% Nat32.fromIntWrap(j); 130 | hash[4 * i + j] := Nat8.fromIntWrap(Nat32.toNat(s[i] >> k)); 131 | }; 132 | }; 133 | return Array.freeze(hash); 134 | }; 135 | 136 | private func block(data : [Nat8]) { 137 | var p = data; 138 | var w = Array.init(64, 0); 139 | while (p.size() >= 64) { 140 | var j = 0; 141 | for (i in Iter.range(0, 15)) { 142 | j := i * 4; 143 | w[i] := 144 | Nat32.fromIntWrap(Nat8.toNat(p[j + 0])) << 24 | 145 | Nat32.fromIntWrap(Nat8.toNat(p[j + 1])) << 16 | 146 | Nat32.fromIntWrap(Nat8.toNat(p[j + 2])) << 08 | 147 | Nat32.fromIntWrap(Nat8.toNat(p[j + 3])) << 00; 148 | }; 149 | var v1 : Nat32 = 0; 150 | var v2 : Nat32 = 0; 151 | var t1 : Nat32 = 0; 152 | var t2 : Nat32 = 0; 153 | for (i in Iter.range(16, 63)) { 154 | v1 := w[i - 02]; 155 | v2 := w[i - 15]; 156 | t1 := rot(v1, 17) ^ rot(v1, 19) ^ (v1 >> 10); 157 | t2 := rot(v2, 07) ^ rot(v2, 18) ^ (v2 >> 03); 158 | w[i] := 159 | t1 +% w[i - 07] +% 160 | t2 +% w[i - 16]; 161 | }; 162 | var a = s[0]; 163 | var b = s[1]; 164 | var c = s[2]; 165 | var d = s[3]; 166 | var e = s[4]; 167 | var f = s[5]; 168 | var g = s[6]; 169 | var h = s[7]; 170 | for (i in Iter.range(0, 63)) { 171 | t1 := rot(e, 06) ^ rot(e, 11) ^ rot(e, 25); 172 | t1 +%= (e & f) ^ (^ e & g) +% h +% K[i] +% w[i]; 173 | t2 := rot(a, 02) ^ rot(a, 13) ^ rot(a, 22); 174 | t2 +%= (a & b) ^ (a & c) ^ (b & c); 175 | h := g; 176 | g := f; 177 | f := e; 178 | e := d +% t1; 179 | d := c; 180 | c := b; 181 | b := a; 182 | a := t1 +% t2; 183 | }; 184 | s[0] +%= a; 185 | s[1] +%= b; 186 | s[2] +%= c; 187 | s[3] +%= d; 188 | s[4] +%= e; 189 | s[5] +%= f; 190 | s[6] +%= g; 191 | s[7] +%= h; 192 | p := Array.tabulate(p.size() - 64, func (i) { 193 | return p[i + 64]; 194 | }); 195 | }; 196 | }; 197 | }; 198 | 199 | private let rot : (Nat32, Nat32) -> Nat32 = Nat32.bitrotRight; 200 | }; 201 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the 13 | copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other 16 | entities that control, are controlled by, or are under common control with 17 | that entity. For the purposes of this definition, "control" means (i) the 18 | power, direct or indirect, to cause the direction or management of such 19 | entity, whether by contract or otherwise, or (ii) ownership of fifty percent 20 | (50%) or more of the outstanding shares, or (iii) beneficial ownership of 21 | such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity exercising 24 | permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation source, and 28 | configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical transformation 31 | or translation of a Source form, including but not limited to compiled 32 | object code, generated documentation, and conversions to other media types. 33 | 34 | "Work" shall mean the work of authorship, whether in Source or Object form, 35 | made available under the License, as indicated by a copyright notice that is 36 | included in or attached to the work (an example is provided in the Appendix 37 | below). 38 | 39 | "Derivative Works" shall mean any work, whether in Source or Object form, 40 | that is based on (or derived from) the Work and for which the editorial 41 | revisions, annotations, elaborations, or other modifications represent, as a 42 | whole, an original work of authorship. For the purposes of this License, 43 | Derivative Works shall not include works that remain separable from, or 44 | merely link (or bind by name) to the interfaces of, the Work and Derivative 45 | Works thereof. 46 | 47 | "Contribution" shall mean any work of authorship, including the original 48 | version of the Work and any modifications or additions to that Work or 49 | Derivative Works thereof, that is intentionally submitted to Licensor for 50 | inclusion in the Work by the copyright owner or by an individual or Legal 51 | Entity authorized to submit on behalf of the copyright owner. For the 52 | purposes of this definition, "submitted" means any form of electronic, 53 | verbal, or written communication sent to the Licensor or its 54 | representatives, including but not limited to communication on electronic 55 | mailing lists, source code control systems, and issue tracking systems that 56 | are managed by, or on behalf of, the Licensor for the purpose of discussing 57 | and improving the Work, but excluding communication that is conspicuously 58 | marked or otherwise designated in writing by the copyright owner as "Not a 59 | Contribution." 60 | 61 | "Contributor" shall mean Licensor and any individual or Legal Entity on 62 | behalf of whom a Contribution has been received by Licensor and subsequently 63 | incorporated within the Work. 64 | 65 | 2. Grant of Copyright License. Subject to the terms and conditions of this 66 | License, each Contributor hereby grants to You a perpetual, worldwide, 67 | non-exclusive, no-charge, royalty-free, irrevocable copyright license to 68 | reproduce, prepare Derivative Works of, publicly display, publicly perform, 69 | sublicense, and distribute the Work and such Derivative Works in Source or 70 | Object form. 71 | 72 | 3. Grant of Patent License. Subject to the terms and conditions of this 73 | License, each Contributor hereby grants to You a perpetual, worldwide, 74 | non-exclusive, no-charge, royalty-free, irrevocable (except as stated in 75 | this section) patent license to make, have made, use, offer to sell, sell, 76 | import, and otherwise transfer the Work, where such license applies only to 77 | those patent claims licensable by such Contributor that are necessarily 78 | infringed by their Contribution(s) alone or by combination of their 79 | Contribution(s) with the Work to which such Contribution(s) was submitted. 80 | If You institute patent litigation against any entity (including a 81 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 82 | Contribution incorporated within the Work constitutes direct or contributory 83 | patent infringement, then any patent licenses granted to You under this 84 | License for that Work shall terminate as of the date such litigation is 85 | filed. 86 | 87 | 4. Redistribution. You may reproduce and distribute copies of the Work or 88 | Derivative Works thereof in any medium, with or without modifications, and 89 | in Source or Object form, provided that You meet the following conditions: 90 | 91 | a. You must give any other recipients of the Work or Derivative Works a 92 | copy of this License; and 93 | 94 | b. You must cause any modified files to carry prominent notices stating 95 | that You changed the files; and 96 | 97 | c. You must retain, in the Source form of any Derivative Works that You 98 | distribute, all copyright, patent, trademark, and attribution notices 99 | from the Source form of the Work, excluding those notices that do not 100 | pertain to any part of the Derivative Works; and 101 | 102 | d. If the Work includes a "NOTICE" text file as part of its distribution, 103 | then any Derivative Works that You distribute must include a readable 104 | copy of the attribution notices contained within such NOTICE file, 105 | excluding those notices that do not pertain to any part of the Derivative 106 | Works, in at least one of the following places: within a NOTICE text file 107 | distributed as part of the Derivative Works; within the Source form or 108 | documentation, if provided along with the Derivative Works; or, within a 109 | display generated by the Derivative Works, if and wherever such 110 | third-party notices normally appear. The contents of the NOTICE file are 111 | for informational purposes only and do not modify the License. You may 112 | add Your own attribution notices within Derivative Works that You 113 | distribute, alongside or as an addendum to the NOTICE text from the Work, 114 | provided that such additional attribution notices cannot be construed as 115 | modifying the License. 116 | 117 | You may add Your own copyright statement to Your modifications and may 118 | provide additional or different license terms and conditions for use, 119 | reproduction, or distribution of Your modifications, or for any such 120 | Derivative Works as a whole, provided Your use, reproduction, and 121 | distribution of the Work otherwise complies with the conditions stated in 122 | this License. 123 | 124 | 5. Submission of Contributions. Unless You explicitly state otherwise, any 125 | Contribution intentionally submitted for inclusion in the Work by You to the 126 | Licensor shall be under the terms and conditions of this License, without 127 | any additional terms or conditions. Notwithstanding the above, nothing 128 | herein shall supersede or modify the terms of any separate license agreement 129 | you may have executed with Licensor regarding such Contributions. 130 | 131 | 6. Trademarks. This License does not grant permission to use the trade names, 132 | trademarks, service marks, or product names of the Licensor, except as 133 | required for reasonable and customary use in describing the origin of the 134 | Work and reproducing the content of the NOTICE file. 135 | 136 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in 137 | writing, Licensor provides the Work (and each Contributor provides its 138 | Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 139 | KIND, either express or implied, including, without limitation, any 140 | warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or 141 | FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining 142 | the appropriateness of using or redistributing the Work and assume any risks 143 | associated with Your exercise of permissions under this License. 144 | 145 | 8. Limitation of Liability. In no event and under no legal theory, whether in 146 | tort (including negligence), contract, or otherwise, unless required by 147 | applicable law (such as deliberate and grossly negligent acts) or agreed to 148 | in writing, shall any Contributor be liable to You for damages, including 149 | any direct, indirect, special, incidental, or consequential damages of any 150 | character arising as a result of this License or out of the use or inability 151 | to use the Work (including but not limited to damages for loss of goodwill, 152 | work stoppage, computer failure or malfunction, or any and all other 153 | commercial damages or losses), even if such Contributor has been advised of 154 | the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or 157 | Derivative Works thereof, You may choose to offer, and charge a fee for, 158 | acceptance of support, warranty, indemnity, or other liability obligations 159 | and/or rights consistent with this License. However, in accepting such 160 | obligations, You may act only on Your own behalf and on Your sole 161 | responsibility, not on behalf of any other Contributor, and only if You 162 | agree to indemnify, defend, and hold each Contributor harmless for any 163 | liability incurred by, or claims asserted against, such Contributor by 164 | reason of your accepting any such warranty or additional liability. 165 | 166 | END OF TERMS AND CONDITIONS 167 | 168 | LLVM EXCEPTION TO THE APACHE 2.0 LICENSE 169 | 170 | As an exception, if, as a result of your compiling your source code, portions 171 | of this Software are embedded into an Object form of such source code, you may 172 | redistribute such embedded portions in such Object form without complying with 173 | the conditions of Sections 4(a), 4(b) and 4(d) of the License. 174 | 175 | In addition, if you combine or link compiled forms of this Software with 176 | software that is licensed under the GPLv2 ("Combined Software") and if a court 177 | of competent jurisdiction determines that the patent provision (Section 3), the 178 | indemnity provision (Section 9) or other Section of the License conflicts with 179 | the conditions of the GPLv2, you may retroactively and prospectively choose to 180 | deem waived or otherwise exclude such Section(s) of the License, but only in 181 | their entirety and only with respect to the Combined Software. 182 | 183 | END OF LLVM EXCEPTION 184 | 185 | APPENDIX: How to apply the Apache License to your work. 186 | 187 | To apply the Apache License to your work, attach the following boilerplate 188 | notice, with the fields enclosed by brackets "[]" replaced with your own 189 | identifying information. (Don't include the brackets!) The text should be 190 | enclosed in the appropriate comment syntax for the file format. We also 191 | recommend that a file or class name and description of purpose be included on 192 | the same "printed page" as the copyright notice for easier identification 193 | within third-party archives. 194 | 195 | Copyright [yyyy] [name of copyright owner] 196 | 197 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 198 | this file except in compliance with the License. You may obtain a copy of the 199 | License at 200 | 201 | http://www.apache.org/licenses/LICENSE-2.0 202 | 203 | Unless required by applicable law or agreed to in writing, software distributed 204 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 205 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 206 | specific language governing permissions and limitations under the License. 207 | 208 | END OF APPENDIX 209 | -------------------------------------------------------------------------------- /test/Test.mo: -------------------------------------------------------------------------------- 1 | /** 2 | * Module : Test.mo 3 | * Description : Unit tests. 4 | * Copyright : 2021 DFINITY Stiftung 5 | * License : Apache 2.0 with LLVM Exception 6 | * Maintainer : Enzo Haussecker 7 | * Stability : Stable 8 | */ 9 | 10 | import Array "mo:base/Array"; 11 | import SHA256 "../src/SHA256"; 12 | 13 | type Test = { 14 | data : [Nat8]; 15 | expect : [Nat8]; 16 | }; 17 | 18 | let tests = [ 19 | { 20 | data = [ 21 | ] : [Nat8]; 22 | expect = [ 23 | 227, 176, 196, 066, 152, 252, 028, 020, 24 | 154, 251, 244, 200, 153, 111, 185, 036, 25 | 039, 174, 065, 228, 100, 155, 147, 076, 26 | 164, 149, 153, 027, 120, 082, 184, 085, 27 | ] : [Nat8]; 28 | }, 29 | { 30 | data = [ 31 | 097, 32 | ] : [Nat8]; 33 | expect = [ 34 | 202, 151, 129, 018, 202, 027, 189, 202, 35 | 250, 194, 049, 179, 154, 035, 220, 077, 36 | 167, 134, 239, 248, 020, 124, 078, 114, 37 | 185, 128, 119, 133, 175, 238, 072, 187, 38 | ] : [Nat8]; 39 | }, 40 | { 41 | data = [ 42 | 097, 098, 43 | ] : [Nat8]; 44 | expect = [ 45 | 251, 142, 032, 252, 046, 076, 063, 036, 46 | 140, 096, 195, 155, 214, 082, 243, 193, 47 | 052, 114, 152, 187, 151, 123, 139, 077, 48 | 089, 003, 184, 080, 085, 098, 006, 003, 49 | ] : [Nat8]; 50 | }, 51 | { 52 | data = [ 53 | 097, 098, 099, 54 | ] : [Nat8]; 55 | expect = [ 56 | 186, 120, 022, 191, 143, 001, 207, 234, 57 | 065, 065, 064, 222, 093, 174, 034, 035, 58 | 176, 003, 097, 163, 150, 023, 122, 156, 59 | 180, 016, 255, 097, 242, 000, 021, 173, 60 | ] : [Nat8]; 61 | }, 62 | { 63 | data = [ 64 | 097, 098, 099, 100, 65 | ] : [Nat8]; 66 | expect = [ 67 | 136, 212, 038, 111, 212, 230, 051, 141, 68 | 019, 184, 069, 252, 242, 137, 087, 157, 69 | 032, 156, 137, 120, 035, 185, 033, 125, 70 | 163, 225, 097, 147, 111, 003, 021, 137, 71 | ] : [Nat8]; 72 | }, 73 | { 74 | data = [ 75 | 097, 098, 099, 100, 101, 76 | ] : [Nat8]; 77 | expect = [ 78 | 054, 187, 229, 014, 217, 104, 065, 209, 79 | 004, 067, 188, 182, 112, 214, 085, 079, 80 | 010, 052, 183, 097, 190, 103, 236, 156, 81 | 074, 138, 210, 192, 196, 076, 164, 044, 82 | ] : [Nat8]; 83 | }, 84 | { 85 | data = [ 86 | 097, 098, 099, 100, 101, 102, 87 | ] : [Nat8]; 88 | expect = [ 89 | 190, 245, 126, 199, 245, 058, 109, 064, 90 | 190, 182, 064, 167, 128, 166, 057, 200, 91 | 059, 194, 154, 200, 169, 129, 111, 031, 92 | 198, 197, 198, 220, 217, 060, 071, 033, 93 | ] : [Nat8]; 94 | }, 95 | { 96 | data = [ 97 | 097, 098, 099, 100, 101, 102, 103, 98 | ] : [Nat8]; 99 | expect = [ 100 | 125, 026, 084, 018, 123, 034, 037, 002, 101 | 245, 183, 155, 095, 176, 128, 048, 097, 102 | 021, 042, 068, 249, 043, 055, 226, 060, 103 | 101, 039, 186, 246, 101, 212, 218, 154, 104 | ] : [Nat8]; 105 | }, 106 | { 107 | data = [ 108 | 097, 098, 099, 100, 101, 102, 103, 104, 109 | ] : [Nat8]; 110 | expect = [ 111 | 156, 086, 204, 081, 179, 116, 195, 186, 112 | 024, 146, 016, 213, 182, 212, 191, 087, 113 | 121, 013, 053, 028, 150, 196, 124, 002, 114 | 025, 014, 207, 030, 067, 006, 053, 171, 115 | ] : [Nat8]; 116 | }, 117 | { 118 | data = [ 119 | 097, 098, 099, 100, 101, 102, 103, 104, 120 | 105, 121 | ] : [Nat8]; 122 | expect = [ 123 | 025, 204, 002, 242, 109, 244, 060, 197, 124 | 113, 188, 158, 215, 176, 196, 210, 146, 125 | 036, 163, 236, 034, 149, 041, 034, 023, 126 | 037, 239, 118, 208, 033, 200, 050, 111, 127 | ] : [Nat8]; 128 | }, 129 | { 130 | data = [ 131 | 097, 098, 099, 100, 101, 102, 103, 104, 132 | 105, 106, 133 | ] : [Nat8]; 134 | expect = [ 135 | 114, 057, 147, 097, 218, 106, 119, 084, 136 | 254, 201, 134, 220, 165, 183, 203, 175, 137 | 028, 129, 010, 040, 222, 212, 171, 175, 138 | 086, 178, 016, 109, 006, 203, 120, 176, 139 | ] : [Nat8]; 140 | }, 141 | { 142 | data = [ 143 | 068, 105, 115, 099, 097, 114, 100, 032, 144 | 109, 101, 100, 105, 099, 105, 110, 101, 145 | 032, 109, 111, 114, 101, 032, 116, 104, 146 | 097, 110, 032, 116, 119, 111, 032, 121, 147 | 101, 097, 114, 115, 032, 111, 108, 100, 148 | 046, 149 | ] : [Nat8]; 150 | expect = [ 151 | 161, 068, 006, 028, 039, 031, 021, 045, 152 | 164, 209, 081, 003, 069, 008, 254, 209, 153 | 193, 056, 184, 201, 118, 051, 157, 226, 154 | 041, 195, 187, 109, 075, 187, 079, 206, 155 | ] : [Nat8]; 156 | }, 157 | { 158 | data = [ 159 | 072, 101, 032, 119, 104, 111, 032, 104, 160 | 097, 115, 032, 097, 032, 115, 104, 097, 161 | 100, 121, 032, 112, 097, 115, 116, 032, 162 | 107, 110, 111, 119, 115, 032, 116, 104, 163 | 097, 116, 032, 110, 105, 099, 101, 032, 164 | 103, 117, 121, 115, 032, 102, 105, 110, 165 | 105, 115, 104, 032, 108, 097, 115, 116, 166 | 046, 167 | ] : [Nat8]; 168 | expect = [ 169 | 109, 174, 092, 170, 113, 058, 016, 173, 170 | 004, 180, 096, 040, 191, 109, 173, 104, 171 | 131, 124, 088, 022, 022, 161, 088, 154, 172 | 038, 090, 017, 040, 141, 075, 181, 196, 173 | ] : [Nat8]; 174 | }, 175 | { 176 | data = [ 177 | 073, 032, 119, 111, 117, 108, 100, 110, 178 | 039, 116, 032, 109, 097, 114, 114, 121, 179 | 032, 104, 105, 109, 032, 119, 105, 116, 180 | 104, 032, 097, 032, 116, 101, 110, 032, 181 | 102, 111, 111, 116, 032, 112, 111, 108, 182 | 101, 046, 183 | ] : [Nat8]; 184 | expect = [ 185 | 174, 122, 112, 042, 149, 009, 003, 157, 186 | 219, 242, 159, 007, 101, 231, 013, 000, 187 | 001, 023, 121, 020, 184, 100, 089, 040, 188 | 077, 171, 139, 052, 140, 045, 206, 063, 189 | ] : [Nat8]; 190 | }, 191 | { 192 | data = [ 193 | 070, 114, 101, 101, 033, 032, 070, 114, 194 | 101, 101, 033, 047, 065, 032, 116, 114, 195 | 105, 112, 047, 116, 111, 032, 077, 097, 196 | 114, 115, 047, 102, 111, 114, 032, 057, 197 | 048, 048, 047, 101, 109, 112, 116, 121, 198 | 032, 106, 097, 114, 115, 047, 066, 117, 199 | 114, 109, 097, 032, 083, 104, 097, 118, 200 | 101, 201 | ] : [Nat8]; 202 | expect = [ 203 | 103, 072, 069, 011, 001, 197, 104, 088, 204 | 103, 021, 041, 029, 250, 062, 224, 024, 205 | 218, 007, 211, 107, 183, 234, 111, 024, 206 | 012, 026, 246, 039, 002, 021, 198, 079, 207 | ] : [Nat8]; 208 | }, 209 | { 210 | data = [ 211 | 084, 104, 101, 032, 100, 097, 121, 115, 212 | 032, 111, 102, 032, 116, 104, 101, 032, 213 | 100, 105, 103, 105, 116, 097, 108, 032, 214 | 119, 097, 116, 099, 104, 032, 097, 114, 215 | 101, 032, 110, 117, 109, 098, 101, 114, 216 | 101, 100, 046, 032, 032, 045, 084, 111, 217 | 109, 032, 083, 116, 111, 112, 112, 097, 218 | 114, 100, 219 | ] : [Nat8]; 220 | expect = [ 221 | 020, 184, 032, 020, 173, 043, 017, 246, 222 | 097, 181, 174, 106, 153, 183, 081, 005, 223 | 194, 255, 172, 039, 140, 208, 113, 205, 224 | 108, 005, 131, 039, 147, 099, 087, 116, 225 | ] : [Nat8]; 226 | }, 227 | { 228 | data = [ 229 | 078, 101, 112, 097, 108, 032, 112, 114, 230 | 101, 109, 105, 101, 114, 032, 119, 111, 231 | 110, 039, 116, 032, 114, 101, 115, 105, 232 | 103, 110, 046, 233 | ] : [Nat8]; 234 | expect = [ 235 | 113, 002, 207, 215, 110, 046, 050, 072, 236 | 137, 238, 206, 093, 108, 065, 146, 027, 237 | 030, 020, 042, 074, 197, 162, 105, 043, 238 | 231, 136, 003, 009, 127, 106, 072, 216, 239 | ] : [Nat8]; 240 | }, 241 | { 242 | data = [ 243 | 070, 111, 114, 032, 101, 118, 101, 114, 244 | 121, 032, 097, 099, 116, 105, 111, 110, 245 | 032, 116, 104, 101, 114, 101, 032, 105, 246 | 115, 032, 097, 110, 032, 101, 113, 117, 247 | 097, 108, 032, 097, 110, 100, 032, 111, 248 | 112, 112, 111, 115, 105, 116, 101, 032, 249 | 103, 111, 118, 101, 114, 110, 109, 101, 250 | 110, 116, 032, 112, 114, 111, 103, 114, 251 | 097, 109, 046, 252 | ] : [Nat8]; 253 | expect = [ 254 | 035, 177, 001, 140, 216, 029, 177, 214, 255 | 121, 131, 197, 247, 065, 124, 068, 218, 256 | 157, 235, 088, 036, 089, 227, 120, 215, 257 | 160, 104, 085, 046, 166, 073, 220, 159, 258 | ] : [Nat8]; 259 | }, 260 | { 261 | data = [ 262 | 072, 105, 115, 032, 109, 111, 110, 101, 263 | 121, 032, 105, 115, 032, 116, 119, 105, 264 | 099, 101, 032, 116, 097, 105, 110, 116, 265 | 101, 100, 058, 032, 039, 116, 097, 105, 266 | 110, 116, 032, 121, 111, 117, 114, 115, 267 | 032, 097, 110, 100, 032, 039, 116, 097, 268 | 105, 110, 116, 032, 109, 105, 110, 101, 269 | 046, 270 | ] : [Nat8]; 271 | expect = [ 272 | 128, 001, 241, 144, 223, 181, 039, 038, 273 | 028, 076, 252, 171, 112, 201, 142, 128, 274 | 151, 167, 161, 146, 033, 041, 188, 064, 275 | 150, 149, 014, 087, 199, 153, 154, 090, 276 | ] : [Nat8]; 277 | }, 278 | { 279 | data = [ 280 | 084, 104, 101, 114, 101, 032, 105, 115, 281 | 032, 110, 111, 032, 114, 101, 097, 115, 282 | 111, 110, 032, 102, 111, 114, 032, 097, 283 | 110, 121, 032, 105, 110, 100, 105, 118, 284 | 105, 100, 117, 097, 108, 032, 116, 111, 285 | 032, 104, 097, 118, 101, 032, 097, 032, 286 | 099, 111, 109, 112, 117, 116, 101, 114, 287 | 032, 105, 110, 032, 116, 104, 101, 105, 288 | 114, 032, 104, 111, 109, 101, 046, 032, 289 | 045, 075, 101, 110, 032, 079, 108, 115, 290 | 101, 110, 044, 032, 049, 057, 055, 055, 291 | ] : [Nat8]; 292 | expect = [ 293 | 140, 135, 222, 182, 085, 005, 195, 153, 294 | 062, 178, 075, 122, 021, 012, 065, 085, 295 | 232, 046, 238, 105, 096, 207, 012, 058, 296 | 129, 020, 255, 115, 109, 105, 202, 213, 297 | ] : [Nat8]; 298 | }, 299 | { 300 | data = [ 301 | 073, 116, 039, 115, 032, 097, 032, 116, 302 | 105, 110, 121, 032, 099, 104, 097, 110, 303 | 103, 101, 032, 116, 111, 032, 116, 104, 304 | 101, 032, 099, 111, 100, 101, 032, 097, 305 | 110, 100, 032, 110, 111, 116, 032, 099, 306 | 111, 109, 112, 108, 101, 116, 101, 108, 307 | 121, 032, 100, 105, 115, 103, 117, 115, 308 | 116, 105, 110, 103, 046, 032, 045, 032, 309 | 066, 111, 098, 032, 077, 097, 110, 099, 310 | 104, 101, 107, 311 | ] : [Nat8]; 312 | expect = [ 313 | 191, 176, 166, 122, 025, 205, 236, 054, 314 | 070, 073, 139, 046, 015, 117, 027, 221, 315 | 196, 027, 186, 075, 127, 048, 008, 027, 316 | 011, 147, 042, 173, 033, 077, 022, 215, 317 | ] : [Nat8]; 318 | }, 319 | { 320 | data = [ 321 | 115, 105, 122, 101, 058, 032, 032, 097, 322 | 046, 111, 117, 116, 058, 032, 032, 098, 323 | 097, 100, 032, 109, 097, 103, 105, 099, 324 | ] : [Nat8]; 325 | expect = [ 326 | 127, 154, 011, 155, 245, 099, 050, 225, 327 | 159, 090, 014, 193, 173, 156, 020, 037, 328 | 161, 083, 218, 028, 098, 072, 104, 253, 329 | 164, 069, 097, 214, 183, 077, 175, 054, 330 | ] : [Nat8]; 331 | }, 332 | { 333 | data = [ 334 | 084, 104, 101, 032, 109, 097, 106, 111, 335 | 114, 032, 112, 114, 111, 098, 108, 101, 336 | 109, 032, 105, 115, 032, 119, 105, 116, 337 | 104, 032, 115, 101, 110, 100, 109, 097, 338 | 105, 108, 046, 032, 032, 045, 077, 097, 339 | 114, 107, 032, 072, 111, 114, 116, 111, 340 | 110, 341 | ] : [Nat8]; 342 | expect = [ 343 | 177, 063, 129, 184, 170, 217, 227, 102, 344 | 104, 121, 175, 025, 136, 097, 064, 144, 345 | 079, 127, 066, 158, 240, 131, 040, 097, 346 | 149, 152, 042, 117, 136, 133, 140, 252, 347 | ] : [Nat8]; 348 | }, 349 | { 350 | data = [ 351 | 071, 105, 118, 101, 032, 109, 101, 032, 352 | 097, 032, 114, 111, 099, 107, 044, 032, 353 | 112, 097, 112, 101, 114, 032, 097, 110, 354 | 100, 032, 115, 099, 105, 115, 115, 111, 355 | 114, 115, 032, 097, 110, 100, 032, 073, 356 | 032, 119, 105, 108, 108, 032, 109, 111, 357 | 118, 101, 032, 116, 104, 101, 032, 119, 358 | 111, 114, 108, 100, 046, 032, 032, 067, 359 | 067, 070, 101, 115, 116, 111, 111, 110, 360 | ] : [Nat8]; 361 | expect = [ 362 | 178, 108, 056, 214, 021, 025, 232, 148, 363 | 072, 012, 112, 200, 055, 078, 163, 090, 364 | 160, 173, 005, 178, 174, 061, 102, 116, 365 | 238, 197, 245, 042, 105, 048, 094, 212, 366 | ] : [Nat8]; 367 | }, 368 | { 369 | data = [ 370 | 073, 102, 032, 116, 104, 101, 032, 101, 371 | 110, 101, 109, 121, 032, 105, 115, 032, 372 | 119, 105, 116, 104, 105, 110, 032, 114, 373 | 097, 110, 103, 101, 044, 032, 116, 104, 374 | 101, 110, 032, 115, 111, 032, 097, 114, 375 | 101, 032, 121, 111, 117, 046, 376 | ] : [Nat8]; 377 | expect = [ 378 | 004, 157, 094, 038, 212, 241, 002, 034, 379 | 205, 132, 026, 017, 158, 056, 189, 141, 380 | 046, 013, 017, 041, 114, 134, 136, 068, 381 | 149, 117, 212, 255, 066, 184, 066, 193, 382 | ] : [Nat8]; 383 | }, 384 | { 385 | data = [ 386 | 073, 116, 039, 115, 032, 119, 101, 108, 387 | 108, 032, 119, 101, 032, 099, 097, 110, 388 | 110, 111, 116, 032, 104, 101, 097, 114, 389 | 032, 116, 104, 101, 032, 115, 099, 114, 390 | 101, 097, 109, 115, 047, 084, 104, 097, 391 | 116, 032, 119, 101, 032, 099, 114, 101, 392 | 097, 116, 101, 032, 105, 110, 032, 111, 393 | 116, 104, 101, 114, 115, 039, 032, 100, 394 | 114, 101, 097, 109, 115, 046, 395 | ] : [Nat8]; 396 | expect = [ 397 | 014, 017, 104, 056, 227, 204, 028, 026, 398 | 020, 205, 004, 083, 151, 226, 155, 077, 399 | 008, 122, 161, 027, 008, 083, 252, 105, 400 | 236, 130, 233, 003, 048, 214, 009, 073, 401 | ] : [Nat8]; 402 | }, 403 | { 404 | data = [ 405 | 089, 111, 117, 032, 114, 101, 109, 105, 406 | 110, 100, 032, 109, 101, 032, 111, 102, 407 | 032, 097, 032, 084, 086, 032, 115, 104, 408 | 111, 119, 044, 032, 098, 117, 116, 032, 409 | 116, 104, 097, 116, 039, 115, 032, 097, 410 | 108, 108, 032, 114, 105, 103, 104, 116, 411 | 058, 032, 073, 032, 119, 097, 116, 099, 412 | 104, 032, 105, 116, 032, 097, 110, 121, 413 | 119, 097, 121, 046, 414 | ] : [Nat8]; 415 | expect = [ 416 | 079, 125, 142, 181, 188, 241, 029, 226, 417 | 165, 107, 151, 016, 033, 164, 068, 170, 418 | 078, 175, 214, 236, 208, 243, 007, 181, 419 | 016, 158, 078, 119, 108, 208, 254, 070, 420 | ] : [Nat8]; 421 | }, 422 | { 423 | data = [ 424 | 067, 032, 105, 115, 032, 097, 115, 032, 425 | 112, 111, 114, 116, 097, 098, 108, 101, 426 | 032, 097, 115, 032, 083, 116, 111, 110, 427 | 101, 104, 101, 100, 103, 101, 033, 033, 428 | ] : [Nat8]; 429 | expect = [ 430 | 097, 192, 204, 076, 075, 216, 064, 109, 431 | 081, 032, 179, 251, 078, 188, 049, 206, 432 | 135, 102, 124, 022, 047, 041, 070, 139, 433 | 060, 119, 150, 117, 168, 090, 235, 206, 434 | ] : [Nat8]; 435 | }, 436 | { 437 | data = [ 438 | 069, 118, 101, 110, 032, 105, 102, 032, 439 | 073, 032, 099, 111, 117, 108, 100, 032, 440 | 098, 101, 032, 083, 104, 097, 107, 101, 441 | 115, 112, 101, 097, 114, 101, 044, 032, 442 | 073, 032, 116, 104, 105, 110, 107, 032, 443 | 073, 032, 115, 104, 111, 117, 108, 100, 444 | 032, 115, 116, 105, 108, 108, 032, 099, 445 | 104, 111, 111, 115, 101, 032, 116, 111, 446 | 032, 098, 101, 032, 070, 097, 114, 097, 447 | 100, 097, 121, 046, 032, 045, 032, 065, 448 | 046, 032, 072, 117, 120, 108, 101, 121, 449 | ] : [Nat8]; 450 | expect = [ 451 | 031, 178, 235, 054, 136, 009, 060, 074, 452 | 063, 128, 205, 135, 165, 084, 126, 044, 453 | 233, 064, 164, 249, 035, 036, 058, 121, 454 | 162, 161, 226, 066, 034, 006, 147, 172, 455 | ] : [Nat8]; 456 | }, 457 | { 458 | data = [ 459 | 084, 104, 101, 032, 102, 117, 103, 097, 460 | 099, 105, 116, 121, 032, 111, 102, 032, 461 | 097, 032, 099, 111, 110, 115, 116, 105, 462 | 116, 117, 101, 110, 116, 032, 105, 110, 463 | 032, 097, 032, 109, 105, 120, 116, 117, 464 | 114, 101, 032, 111, 102, 032, 103, 097, 465 | 115, 101, 115, 032, 097, 116, 032, 097, 466 | 032, 103, 105, 118, 101, 110, 032, 116, 467 | 101, 109, 112, 101, 114, 097, 116, 117, 468 | 114, 101, 032, 105, 115, 032, 112, 114, 469 | 111, 112, 111, 114, 116, 105, 111, 110, 470 | 097, 108, 032, 116, 111, 032, 105, 116, 471 | 115, 032, 109, 111, 108, 101, 032, 102, 472 | 114, 097, 099, 116, 105, 111, 110, 046, 473 | 032, 032, 076, 101, 119, 105, 115, 045, 474 | 082, 097, 110, 100, 097, 108, 108, 032, 475 | 082, 117, 108, 101, 476 | ] : [Nat8]; 477 | expect = [ 478 | 057, 085, 133, 206, 048, 097, 123, 098, 479 | 200, 011, 147, 232, 032, 140, 232, 102, 480 | 212, 237, 200, 017, 161, 119, 253, 180, 481 | 184, 045, 057, 017, 216, 105, 100, 035, 482 | ] : [Nat8]; 483 | }, 484 | { 485 | data = [ 486 | 072, 111, 119, 032, 099, 097, 110, 032, 487 | 121, 111, 117, 032, 119, 114, 105, 116, 488 | 101, 032, 097, 032, 098, 105, 103, 032, 489 | 115, 121, 115, 116, 101, 109, 032, 119, 490 | 105, 116, 104, 111, 117, 116, 032, 067, 491 | 043, 043, 063, 032, 032, 045, 080, 097, 492 | 117, 108, 032, 071, 108, 105, 099, 107, 493 | ] : [Nat8]; 494 | expect = [ 495 | 079, 155, 024, 154, 019, 208, 048, 131, 496 | 130, 105, 220, 232, 070, 177, 106, 028, 497 | 233, 206, 129, 254, 099, 230, 093, 226, 498 | 246, 054, 134, 051, 054, 169, 143, 230, 499 | ] : [Nat8]; 500 | }, 501 | ]; 502 | 503 | func eq(a : Nat8, b : Nat8) : Bool { 504 | return a == b; 505 | }; 506 | 507 | for (test in tests.vals()) { 508 | let expect = test.expect; 509 | let actual = SHA256.sha256(test.data); 510 | assert(Array.equal(expect, actual, eq)); 511 | }; 512 | --------------------------------------------------------------------------------