Skip to content

Commit

Permalink
New files
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Green committed Nov 27, 2023
1 parent 0a8b1bf commit 55f1e06
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
28 changes: 28 additions & 0 deletions package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
;;; package.asd
;;;
;;; SPDX-License-Identifier: MIT
;;;
;;; Copyright (C) 2023 Anthony Green <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining a copy
;;; of this software and associated documentation files (the "Software"), to deal
;;; in the Software without restriction, including without limitation the rights
;;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;;; copies of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be included in all
;;; copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;;; SOFTWARE.
;;;

(defpackage #:privacy-output-stream
(:use #:cl #:trivial-gray-streams)
(:export privacy-output-stream secrets))
34 changes: 34 additions & 0 deletions privacy-output-stream.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
;;; privacy-output-stream.asd
;;;
;;; SPDX-License-Identifier: MIT
;;;
;;; Copyright (C) 2023 Anthony Green <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining a copy
;;; of this software and associated documentation files (the "Software"), to deal
;;; in the Software without restriction, including without limitation the rights
;;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;;; copies of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be included in all
;;; copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;;; SOFTWARE.
;;;

(asdf:defsystem #:privacy-output-stream
:description "A privacy preserving output stream"
:author "Anthony Green <[email protected]>"
:license "MIT"
:version (:read-file-form "version.sexp")
:serial t
:components ((:file "package")
(:file "privacy-output-stream"))
:depends-on (:trivial-gray-streams))
35 changes: 35 additions & 0 deletions privacy-output-stream.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
;;; privacy-output-stream
;;;
;;; SPDX-License-Identifier: MIT
;;;
;;; Copyright (C) 2023 Anthony Green <[email protected]>

(in-package :privacy-output-stream)

(defclass privacy-output-stream (fundamental-character-output-stream)
((stream :initarg :stream :reader stream-of)
(secrets :initarg :secrets :reader secrets :initform nil)))

(defmethod stream-element-type ((stream privacy-output-stream))
(stream-element-type (stream-of stream)))

(defmethod close ((stream privacy-output-stream) &key abort)
(close (stream-of stream) :abort abort))

(defmethod stream-force-output ((stream privacy-output-stream))
(force-output (stream-of stream)))

(defmethod stream-write-char ((stream privacy-output-stream)
char)
(write-char char (stream-of stream)))

(defmethod stream-write-string ((stream privacy-output-stream)
string &optional start end)
(dolist (secret (secrets stream))
(setf string (with-output-to-string (out)
(loop with start = 0
for pos = (search secret string :start2 start)
do (write-string string out :start start :end pos)
when pos do (dotimes (x (length secret)) (write-char #\* out))
while pos do (setf start (+ pos (length secret)))))))
(write-string string (stream-of stream) :start start :end end))
1 change: 1 addition & 0 deletions version.sexp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"1.0"

0 comments on commit 55f1e06

Please sign in to comment.