From 39a5f558b270630156ef3ea96f74340b7183d467 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Thu, 17 Jun 2021 13:04:26 -0700 Subject: [PATCH] Crypto::Secret::Key used Sodium::SecureBuffer when available --- src/crypto-secret/key.cr | 18 +++++++++++------- src/crypto-secret/secret.cr | 1 - 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/crypto-secret/key.cr b/src/crypto-secret/key.cr index 3fb10e4..b10323b 100644 --- a/src/crypto-secret/key.cr +++ b/src/crypto-secret/key.cr @@ -1,12 +1,16 @@ require "./bidet" -module Crypto::Secret - # Use this class for holding small amounts of sensitive data such as crypto keys - # - # Underlying implentation subject to change - # +# Use this class for holding small amounts of sensitive data such as crypto keys +# +# Underlying implentation subject to change +# +# Uses `Sodium::SecureBuffer` If "sodium" is required before "crypto-secret" +{% if @type.has_constant?("Sodium") %} + class Crypto::Secret::Key < ::Sodum::SecureBuffer + end +{% else %} # TODO: mlock # TODO: mprotect - class Key < Bidet + class Crypto::Secret::Key < ::Crypto::Secret::Bidet end -end +{% end %} diff --git a/src/crypto-secret/secret.cr b/src/crypto-secret/secret.cr index 08f0265..4e23287 100644 --- a/src/crypto-secret/secret.cr +++ b/src/crypto-secret/secret.cr @@ -106,7 +106,6 @@ module Crypto::Secret end end - # Marks a region allocated using as read & write depending on implementation. abstract def readwrite : self # Marks a region allocated using as read-only depending on implementation.