[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 02/324: Define hashcodes
From: |
gnunet |
Subject: |
[gnunet-scheme] 02/324: Define hashcodes |
Date: |
Tue, 21 Sep 2021 13:20:42 +0200 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit 525d153dfef3925887f0beb649223bd2d3ccf00d
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Mon Nov 2 14:10:01 2020 +0100
Define hashcodes
---
gnu/gnunet/hashcode.scm | 84 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/gnu/gnunet/hashcode.scm b/gnu/gnunet/hashcode.scm
new file mode 100644
index 0000000..de68267
--- /dev/null
+++ b/gnu/gnunet/hashcode.scm
@@ -0,0 +1,84 @@
+;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
+;; Copyright (C) 2006--2020 GNUnet e.V.
+;; Copyright (C) 2020 Maxime Devos <maxime.devos@student.kuleuven.be>
+;;
+;; GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL-3.0-or-later
+;;
+;; As a special exception to the GNU Affero General Public License,
+;; the file may be relicensed under any license used for
+;; most source code of GNUnet 0.13.1, or later versions, as published by
+;; GNUnet e.V.
+
+;; Extracted from src/include/gnunet_common.h
+
+(library (gnu gnunet hashcode)
+ (export hashcode-bit-length hashcode-u8-length
+ short-hashcode-bit-length short-hashcode-u8-length
+ hashcode? short-hashcode?
+ bv->hashcode bv->short-hashcode
+ hashcode->bv short-hashcode->bv)
+ (import (rnrs base)
+ (rnrs control)
+ (rnrs records syntactic)
+ (rnrs bytevectors))
+
+ (define hashcode-bit-length 512)
+ (define short-hashcode-bit-length 256)
+ (define hashcode-u8-length (/ hashcode-bit-length 8))
+ (define short-hashcode-u8-length (/ short-hashcode-bit-length 8))
+
+ ;; A 512-bit hashcode. These are the default length for GNUnet,
+ ;; using SHA-512.
+ (define-record-type (<hashcode> %make-hashcode hashcode?)
+ (fields (immutable bv %hashcode-bv))
+ (opaque #t)
+ (sealed #t))
+
+ ;; A 256-bit hashcode. Used under special conditions, like when space
+ ;; is critical and security is not impacted by it.
+ (define-record-type (<short-hashcode> %make-short-hashcode short-hashcode?)
+ (fields (immutable bv %short-hashcode-bv))
+ (opaque #t)
+ (sealed #t))
+
+ (define (bv->something %wrap length)
+ (case-lambda
+ "Read something from a bytevector"
+ ((bv) ; whole bytevector
+ (assert (= (bytevector-length bv) length))
+ (%wrap (bytevector-copy bv)))
+ ((bv offset) ; part of a bytevector, starting at some offset
+ (assert (<= (+ offset length) (bytevector-length bv)))
+ (let ((bv-new (make-bytevector length)))
+ (bytevector-copy! bv 0 bv-new 0 length)
+ (%wrap bv-new)))))
+
+ (define bv->hashcode
+ (bv->something %make-hashcode hashcode-u8-length))
+ (define bv->short-hashcode
+ (bv->something %make-short-hashcode short-hashcode-u8-length))
+
+ (define (hashcode->bv hashcode)
+ "Extract the bytevector corresponding to @var{hashcode}
+(read-only)"
+ (bytevector-copy (%hashcode-bv hashcode)))
+
+ (define (short-hashcode->bv hashcode)
+ "Extract the bytevector corresponding to @var{short-hashcode}
+(read-only)"
+ (bytevector-copy (%short-hashcode-bv hashcode))))
+
+
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] branch master created (now 3c91acb), gnunet, 2021/09/21
- [gnunet-scheme] 02/324: Define hashcodes,
gnunet <=
- [gnunet-scheme] 04/324: Define CHK URIs and parsing, gnunet, 2021/09/21
- [gnunet-scheme] 03/324: Define (de-)ASCIIification procedures for hash codes, gnunet, 2021/09/21
- [gnunet-scheme] 07/324: Fix some exports and imports, gnunet, 2021/09/21
- [gnunet-scheme] 01/324: New module: (gnu gnunet directory), gnunet, 2021/09/21
- [gnunet-scheme] 10/324: Define a few libextractor metaformats, gnunet, 2021/09/21
- [gnunet-scheme] 13/324: Include the plugin name in item meta-data, gnunet, 2021/09/21
- [gnunet-scheme] 08/324: Define libextractor metatypes, gnunet, 2021/09/21
- [gnunet-scheme] 06/324: Begin defining (gnu gnunet metadata), gnunet, 2021/09/21
- [gnunet-scheme] 14/324: Define a new binding construct, gnunet, 2021/09/21
- [gnunet-scheme] 18/324: Fix variable references, gnunet, 2021/09/21