This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-24
Channels
- # announcements (11)
- # babashka (11)
- # beginners (36)
- # biff (14)
- # cider (2)
- # clj-commons (9)
- # clojure (34)
- # clojure-czech (2)
- # clojure-europe (65)
- # clojure-nl (2)
- # clojure-norway (12)
- # clojure-uk (4)
- # clojuredesign-podcast (7)
- # clojurescript (5)
- # cursive (8)
- # deps-new (6)
- # hugsql (1)
- # humbleui (2)
- # hyperfiddle (5)
- # leiningen (21)
- # off-topic (2)
- # polylith (5)
- # practicalli (1)
- # releases (1)
- # sci (64)
- # sql (9)
- # squint (43)
- # test-check (6)
- # vim (7)
hi @borkdude I noticed the Arrays/fill method is missing - while implementing pkcs7 padding for ansible vault (code block in thread). I can probably work around it with Arrays/copyRange + some custom code but was curios as to why it is not there: intention or ??
; java.lang.IllegalArgumentException: No matching method fill found taking 4 args user /home/ieugen/proiecte/clojure/compoje/src/compoje/providers/ansible_vault.clj:3:22
https://github.com/babashka/babashka/blob/2a432d3e802c695391da909601044824183ad053/src/babashka/impl/classes.clj#L91(defn pad-pkcs7
"Inspired from docs:
PKCS7 padding is a generalization of PKCS5 padding (also known as standard padding).
PKCS7 padding works by appending N bytes with the value of chr(N),
where N is the number of bytes required to make the final block of
data the same size as the block size."
[block-size-bits buffer]
(let [block-size-bytes (block-size-bits->bytes block-size-bits)
buffer-size-bytes (int (count buffer))
buffer-with-padding-size (padded-buffer-size block-size-bytes buffer-size-bytes)
n (padding-value block-size-bytes buffer-size-bytes)
padding-required? (pos-int? n)]
(if padding-required?
(let [bytes (byte-array buffer-with-padding-size buffer)
to-index (int (+ buffer-size-bytes n))]
(Arrays/fill bytes buffer-size-bytes to-index (byte n))
bytes)
buffer)))
The reason that not everything is in there is that the Array class pulls in a lot of other stuff which increases the size significantly
I implemented padding- which was the missing part and now I will focus on the API and features
$ ./bb -e '(let [arr (int-array [1 2 3])] (java.util.Arrays/fill arr 2) (into [] arr))'
[2 2 2]
Seems to work now