IRC channel logs


back to list of logs

<ruffni>aaaand what's a Guile way to create a hash for binary data (i.e. file data)? md5sum would do
<RhodiumToad>that's a harder one. not sure there's any built-in crypto functions. you could access an existing md5 library via the FFI
<RhodiumToad>any particular OS involved?
*RhodiumToad not guix user
<ruffni>that's ok :)
<ruffni>`guix search md5` yields a package named "guile-hashing".. i think i'll go with that :)
<ruffni>hmmm.. it's the module called "hashing" in guile's "libraries" section (on the www). but the site ( gives a 404
<lampilelo>you can always open-input-pipe for md5sum
<RhodiumToad>yeah but that requires ugly contortions to get the filename into the command
<RhodiumToad>shell quoting, etc.
<ruffni>guile-hashing seems cool!
<lampilelo>then use open-pipe*, with ffi or wrapper libraries you'll probably need to pipe files directly to the digest function
*RhodiumToad successfully computes md5("foo") using the ffi
<lampilelo>i'd probably extend my nettle wrapper if i needed to hash some files
<ruffni>which library does your md5() come from?
<RhodiumToad>I used openssl's libcrypto
<RhodiumToad>though freebsd has a libmd, but there's some symbol renaming going on there to avoid clashing with libcrypto
<ruffni>hmm.. i'll give the ffi a try soon, this should be faster than the guile-only code in guile-hashing, right?
<lampilelo>although i wonder how do they compare
<RhodiumToad>blugh. you can create applicable structs in goops, but you can't create them with metaclasses, unless you pry off some cover plates using (@@)
<RhodiumToad>in particular it's not sufficient for your metaclass to inherit from <applicable-struct-class>
<lloda>i kinda miss (define-syntax (id s) ...)
<lampilelo>what was (define-syntax (id s) ...)?
<lloda>(define-syntax id (lambda (s) ...))
<lampilelo>i see, so why was it removed?
<lloda>it wasn't removed, i don't think it has ever worked
*lloda too scared of psyntax.scm
<lampilelo>i would be too if i had to look at it
<lampilelo>for now i'm just a beginner when it comes to hygienic macros
<vijaymarupudi>daviid: Some data from using glib's main loop in g-golf for a neovim remote plugin, it works wonderfully! However, it seems like 21% of the program time in tight loops is spent in char-upper-case? and char-lower-case?.
<vijaymarupudi>daviid: Not a blocker for me btw, just sharing in case you were curious :)
<dsmith-work>Happy Friday, Guilers!!
***sneek_ is now known as sneek
<dsmith-work>sneek: botsnack
<dsmith-work>Urr? Just went to build guile:
<dsmith-work>./guile-snarf-docs: 55: mawk: not found
<dsmith-work>mawk ? Why is it looking for that, I wonder
*sneek waves
<ruffni>i'm having troubles calling sha-1 through FFI with an open port. can i inject the open-file port directly as a pointer to sha1?
<dsmith-work>Hmm. a git clean and autogen .... make check worked fine. (With an (exit 77) in standalone/test-out-of-memory because bullseye libgc)
<dsmith-work>ruffni: Is that sha1 expecting a buffer? Or a fd?
<dsmith-work>Buffer most likely
<dsmith-work>ruffni: You will need to read the contents of your file and pass that in. Right now, looks like you are instead passing the scheme port datastructure.
<ruffni>hmmm. thanks :)
<RhodiumToad>ruffni: I have some mostly working examples that I can put up in a bit
<ruffni>RhodiumToad: that'd be great!
<ruffni>yeah, i was wondering exactly *how* you got your md5 call working :)
<RhodiumToad>well I kind of got carried away
<lampilelo>ruffni: a port is not a bytevector you can pass by pointer to an external function, what you need to do is read from the port to a bytevector and then pass its pointer to the function, although SHA1() won't do it for a file because you'd need to load the whole of it to memory
<lampilelo>you'd need to use SHA1_Update and pass it parts of the file in a loop
<ruffni>RhodiumToad: so you're writing a full-fledged, FFI based frontend for libcrypto?
<ruffni>lampilelo: thanks for the clarification!
<lampilelo>also the third argument for SHA1() is a pointer to your output buffer, so what you want to do is create a bytevector with length of SHA_DIGEST_LENGTH and pass its pointer to the function
<lampilelo>you should read the section about FFI from the guile manual
<ruffni>i am :) stupidly though i only read "Void Pointers" instead of the whole title of section 6.19.6 and skipped it
<RhodiumToad>ruffni: I got to the point where I can do this:
<RhodiumToad>(let ((h (make <hash-state> algo: 'algo))) (call-with-input-file "filename" (cut update h <>)) (as-bytes h))
<RhodiumToad>er, algo: 'sha1
<RhodiumToad>(or md5, sha512, etc.)
<RhodiumToad>and even things like ((make <hash-algo> algo: 'md5) (string->utf8 "foo"))
<lampilelo>so where's the code?
<lampilelo>show me, i demand! :P
<RhodiumToad>this is not really cleaned up, it's not an actual module and the error handling is ... sketchy
<lampilelo>oh so that's why you were talking about @@ and goops before
<RhodiumToad>I wanted the <hash-algo> instances to be both kind-of-singletons (can only make one of each algorithm, and trying to make more just returns the existing one),
<RhodiumToad>and also have them be applicable-structs, where applying the algorithm to a bytevector returns the hash
<RhodiumToad>all the applicable-struct stuff can be removed without much trouble
<lampilelo>nice work though
<ruffni>am i missing something or is #:kwarg equivalent to kwarg: when srfi-88 is loaded?
<lampilelo>(begin (use-modules (srfi srfi-88)) (eq? #:kwarg kwarg:)) => #t
<RhodiumToad>if you're wondering why I use init-keyword: #:algo
<RhodiumToad>it's because I like to distinguish between keyword-used-as-keyword (init-keyword:) from keyword-used-as-value (#:algo)
<RhodiumToad>I find #: ugly for keywords used as keywords, which is why I use srfi-88
<ruffni>so, for aesthetic reasons
<RhodiumToad>init-keyword: algo: would have worked just as well
<ruffni>cool, never seen that before!
<daviid>RhodiumToad: dpaste ... isn't tor friendly ...
<RhodiumToad>here's another version:
<RhodiumToad>that strips out the applicable-struct stuff and some of the other undocumented goops tricks (like calling (next-method) with explicit args)
<ruffni>daviid: any suggestions for a friendlier alternative?
<daviid> Error 1020 ... Access denied ... This website is using a security service to protect itself from online attacks.
<daviid>ruffni: at least 3, debian, gnome and sourcehut
<RhodiumToad>yes, appears to be behind cloudflare
<ruffni>daviid: thanks!
<daviid>RhodiumToad: i was interested to follow your goops app-struct endeavor ...
<RhodiumToad>does termbin work for you?
<daviid>RhodiumToad: yes, tx
<RhodiumToad>just inheriting <applicable-struct> works if you don't specify a metaclass, but if you do specify one, it doesn't work without the line commented "ugh!"
<RhodiumToad>(it looks like the vtable-flag-applicable-vtable class flag is for whatever reason not inherited, seems like it should be)
<ruffni>RhodiumToad: are the <hash-algo> instances now singletons? is that why you defined your own metaclass -- realized through (make-hash-table)?
<RhodiumToad>there's at most one algorithm object per algorithm
<RhodiumToad>(make <hash-algo> algo: whatever) returns the existing object if one exists rather than making a new one
<RhodiumToad>that's what the metaclass stuff is for
<ruffni>i think i get it! what a wonderful opportunity to learn about GOOPS metaclasses. thank you!
<RhodiumToad><hash-algo> is a class, and so it would normally be an instance of <class>, so the (make) would normally resolve to (make (_ <class>) ...)
<RhodiumToad>but by making <hash-algo> an instance of something derived from <class>, we can specialize (make) for (make (_ <hash-algo-class>) ...) and make it do something different
<ruffni>i understand :)
<RhodiumToad>make and make-instance are the same generic under the hood, so we only need to define one of them
<ruffni>and is this (next-method) trick documented somewhere? i only find references to no-next-method
<RhodiumToad>which trick? passing args to next-method?
<RhodiumToad>the documentation just says (next-method) calls the next method with the same args as the current one
<RhodiumToad>but it so happens that (next-method ...) works to call it with a completely new set of args
<RhodiumToad>that last part is not documented, I believe I learned it here
<RhodiumToad>(probably the first time I played with applicable-structs)
<ruffni>(next-method) in this case call's the superclasses (initialize initargs) ?
<RhodiumToad>in any method, (next-method) calls the next-most-closely matching method from the list of matching methods
<daviid>fwiw, there're called (the list of) applicable method(s)
<ruffni>so i tried wrapping that code into a module and start writing a super-primitive frontend for it but i get "unknown algorithm".