<< 02-01-2023 >>

00:01:49*byanka joined #nim
00:04:12FromDiscord<Yepoleb> [Edit](https://discord.com/channels/371759389889003530/371759389889003532/1059259611179393114): i was hoping to avoid the explicit slicing ☹️
00:04:49*ixmpp quit (Remote host closed the connection)
00:04:49*droidrage quit (Remote host closed the connection)
00:04:49*qwestion quit (Remote host closed the connection)
00:06:06*ixmpp joined #nim
00:12:54FromDiscord<Yepoleb> can i somehow use the parameter style object initialization with new? I am trying to do this `var x = new Foo(a: 1, b: 2)`. I know how to do it with manually assigning each field.
00:13:13FromDiscord<Elegantbeef> `Foo(a: 1, b: 2)` works for ref object
00:13:28FromDiscord<Elegantbeef> if it's not a ref obj you can do `(ref Foo)(a: 1, b: 2)`
00:14:00FromDiscord<Yepoleb> this implicitly calls new?
00:14:13FromDiscord<Elegantbeef> Yes object constructors for ref objects heap allocate
00:16:22FromDiscord<Yepoleb> perfect, thanks!
00:25:04*azimut joined #nim
00:30:35FromDiscord<@thatrandomperson5-6310e3b26da03> > ↵> Is `ActiveWorker` a ref object?↵> Is it supposed to be?
00:31:18FromDiscord<Elegantbeef> It should be since you're storing the address of a vlaue
00:51:06FromDiscord<@thatrandomperson5-6310e3b26da03> It doesn’t fix the problem
00:57:33*wallabra joined #nim
01:09:23*wallabra_ joined #nim
01:09:53*wallabra quit (Ping timeout: 246 seconds)
01:10:19*wallabra_ is now known as wallabra
01:49:24FromDiscord<Iliketwertles> sent a code paste, see https://play.nim-lang.org/#ix=4k8V
01:49:27FromDiscord<Iliketwertles> what does this mean?
01:50:53FromDiscord<Iliketwertles> i dont think the code thats cut out is important to the error but idk https://media.discordapp.net/attachments/371759389889003532/1059287635346083850/screenshot_2023-01-01-205031.png
01:50:56FromDiscord<Rika> You’re trying to call a variable?
01:51:12FromDiscord<Rika> Second line in the screen shot
01:51:17FromDiscord<Rika> Inside the format string
01:51:22FromDiscord<Rika> You have parentheses
01:51:29FromDiscord<Rika> (edit) "You have ... parentheses" added "extra"
01:51:46FromDiscord<Iliketwertles> oh :FacePalm:
01:51:49FromDiscord<Iliketwertles> thanks
01:59:40*arkurious quit (Quit: Leaving)
02:50:35*azimut quit (Ping timeout: 255 seconds)
03:13:37NimEventerNew thread by GavinRay: How does the `nimsuggest` LSP work with respect to UFCS support in Nim?, see https://forum.nim-lang.org/t/9789
03:22:26*jvinet quit (Remote host closed the connection)
03:47:45*wallabra quit (Ping timeout: 260 seconds)
04:14:28*pbsds quit (Quit: The Lounge - https://thelounge.chat)
04:15:29*pbsds joined #nim
04:43:41*wallabra joined #nim
05:07:48NimEventerNew post on r/nim by His_son: Noob question about storing data, see https://reddit.com/r/nim/comments/1013ytj/noob_question_about_storing_data/
07:07:09*rockcavera quit (Remote host closed the connection)
07:14:57FromDiscord<jos> In reply to @Elegantbeef "https://github.com/yglukhov/iface": btw is this like not on nimble or something
07:22:20*kenran joined #nim
07:22:41*kenran quit (Remote host closed the connection)
07:52:39*azimut joined #nim
08:00:30*PMunch joined #nim
08:25:51FromDiscord<xoich (xoich)> hello, is there an Either type in nim? It's like Option, but with the possibility to specify an error if you can't return the value. Considering that nim discourages exceptions it would seems better to use something like this rather than raising.
08:27:16FromDiscord<Clonkk> `std/options` ecists
08:27:18FromDiscord<Clonkk> exists\
08:27:43FromDiscord<xoich (xoich)> I thought you couldn't specify an error with that though?
08:28:27FromDiscord<Clonkk> Well you can always set the option to None to specify errors
08:28:30FromDiscord<Clonkk> Otherwise you have https://github.com/arnetheduck/nim-result
08:30:29FromDiscord<xoich (xoich)> I think nim-result is exactly what I wanted, thanks!
08:32:30FromDiscord<xoich (xoich)> I was hoping to find it in the stdlib, but ok
09:22:25*wallabra quit (Quit: ZNC 1.8.2 - https://znc.in)
09:39:17FromDiscord<voidwalker> less and less hope to find the good stuff in the stdlib.
09:40:30FromDiscord<voidwalker> in the future, it might be that it will only be used to learn nim. for real programs, use aweseomelib
09:59:25PMunchI wouldn't be opposed to creating a meta-package which depends on all the parts being moved out of the stdlib and then have that meta-package be installed by default when installing nimble
10:01:02PMunchBut I agree that the standard library could benefit from having more basic types as well. Makes it easier for libraries to re-use shared components
10:43:38FromDiscord<xoich (xoich)> what is awesomelib?↵(@voidwalker)
10:44:10FromDiscord<voidwalker> some "awesome X" kind of colletion of pacakges. Like the one maintained here : https://github.com/ringabout/awesome-nim
10:44:29FromDiscord<voidwalker> (edit) "colletion" => "collection"
10:47:40FromDiscord<luteva> is there an easy way of searching for projects that use a given lib/package? something like "nimble search dependency=some_lib"↵This could be great to get some real examples or for getting some ideas/inspiration of how to use that lib/package.
10:48:19FromDiscord<federico3> Shipping Nim without batteries included cripples its usability for real world production code
10:48:39FromDiscord<ShalokShalom> Why would that be the case
10:48:46FromDiscord<ShalokShalom> And why do you think it is the case
10:48:54FromDiscord<ShalokShalom> Cause they slim down the stdlib?
10:54:40FromDiscord<voidwalker> In reply to @luteva "is there an easy": search "import <pkgname>" language:nim on github
10:55:44FromDiscord<voidwalker> In reply to @federico3 "Shipping Nim without batteries": I agree, if anything, it should adopt great libs in the stdlib, not externalize them
10:55:59FromDiscord<federico3> Many organizations do supply chain management, they require build environments to be reproducible and the licenses to be vetted. This is much easier to implement if you have a good standard library or a bulkier development "kit" shipped in one archive rather than having to repackage a hundred tiny libraries.
11:06:22FromDiscord<Rika> In reply to @voidwalker "I agree, if anything,": Well are you willing to do the maintenance and work to make it so?
11:07:56FromDiscord<Rika> The reality is that the way the standard library is packaged increases the friction for maintaining such packages within, more than a separate package↵↵Of course there is the benefit of it being much more coherent but I believe there are better ways to have coherence without putting packages in the standard library graveyard
11:08:02*jmdaemon quit (Ping timeout: 246 seconds)
11:08:33FromDiscord<federico3> Yes I am.↵(@Rika)
11:09:15FromDiscord<Rika> Well that’s nice, I don’t have much to say about that other than I look forward to see the progress, seriously
11:09:47FromDiscord<arkanoid> Isn't this solved by using github hash in nimble file require ?
11:10:02FromDiscord<hdbg> What is wrong? https://media.discordapp.net/attachments/371759389889003532/1059428348285161502/image.png
11:10:58FromDiscord<federico3> No, unfortunately that's far from enough as it still needs to use nimble and pull stuff from the Internet to recreate a build environment
11:11:37FromDiscord<arkanoid> There's to learn from nix here
11:12:00FromDiscord<federico3> It's not my decision. There was a proposal to ship additional libraries as part of the release but it was rejected.↵(@Rika)
11:12:23FromDiscord<federico3> Not really. Distributions have been doing this for decades before Nix.
11:12:30FromDiscord<Rika> In reply to @federico3 "It's not my decision.": Why?
11:35:58FromDiscord<Entikan> how do I pre-compile modules so I don't have to constantly recompile them?
11:36:32FromDiscord<Entikan> preferably just in debug mode or something, so it compiles everything on release
11:37:10FromDiscord<Rika> Incremental compilation is not finished but you can experiment with it (I don’t know how exactly)
11:38:08FromDiscord<Entikan> --incremental:on breaks compilation, but nice to know that's what it is for
11:41:17FromDiscord<Entikan> sent a code paste, see https://play.nim-lang.org/#ix=4kac
12:39:20NimEventerNew thread by sls1005: Nim book in Japanese, see https://forum.nim-lang.org/t/9790
12:48:56PMunchIs there a way to get nimble to build two binaries from the same source on installation with different flags?
13:17:36PMunchFigured out a way which works, now NimLSP ships with a `nimlsp_debug` version so you won't have to build it yourself to be able to provide logs :)
13:21:59FromDiscord<Prestige> very nice
13:27:54*droidrage joined #nim
13:41:07*azimut quit (Quit: ZNC - https://znc.in)
13:43:12*azimut joined #nim
14:00:28FromDiscord<luteva> In reply to @voidwalker "search "import <pkgname>" language:nim": this doesn't seem to work.
14:00:55FromDiscord<voidwalker> @luteva click "Code" entry in the lefthand menu
14:01:02FromDiscord<voidwalker> https://github.com/search?q=%22import+binarylang%22+language%3ANim&type=code
14:01:40FromDiscord<luteva> ahh ok i tried the 'man' search
14:02:22FromDiscord<voidwalker> of course, this is for github only. There are a small number of projects only hosted on gitlab.. maybe gitlab has some similar functionality.
14:03:05FromDiscord<voidwalker> Anyone know if Araq reads (or receives in the first place) PMs on discord ?
14:03:45FromDiscord<ringabout> In reply to @voidwalker "Anyone know if Araq": Depends what's the topic
14:03:53FromDiscord<ringabout> (edit) "In reply to @voidwalker "Anyone know if Araq": Depends ... what's" added "on"
14:04:06Amun-Radoes sender know the message was read?
14:04:17Amun-Raf.e. as in fb messenger?
14:04:28FromDiscord<voidwalker> I really want a PDF of his book. destroyed my book attempting to scan it, and the result is not satisfactory, slow page loads, OCR not perfect for code..
14:05:18FromDiscord<voidwalker> I know most people that bought the book were unhappy with not getting a PDF as well, so maybe this issue can be addressed.
14:06:10FromDiscord<ringabout> In reply to @voidwalker "I really want a": You can email him.
14:06:14FromDiscord<voidwalker> This would make many happy. I know he expressed the view that the book should be read on paper, but that's obviously not what most of us want to do
14:06:35FromDiscord<voidwalker> I like to read literature on paper, not tables with ascii codes : P
14:06:56FromDiscord<ringabout> In reply to @ringabout "You can email him.": Here is th email https://github.com/Araq
14:07:00FromDiscord<ringabout> (edit) "th" => "the"
14:07:16FromDiscord<voidwalker> I already pm-ed here.. I will wait a few days for reply before e-mail, so not to spam. Thanks
14:08:28FromDiscord<ringabout> As far as I'm concerned, pming him in some channels may not work.
14:08:42FromDiscord<voidwalker> I pm-ed him, not in channel
14:08:49FromDiscord<voidwalker> DM
14:24:17FromDiscord<luteva> In reply to @voidwalker "<@954521401073754212> click "Code" entry": oh great that worked! Gonna stop programming right now, as what i am working on, does already exist 😄
14:24:49FromDiscord<voidwalker> yeah, good thing to not repeat the same projects over and over if it can be helped. so many things missing
14:26:02FromDiscord<voidwalker> Also I noticed there are lots of projects started with enthusiasm, with great ideas, but never got anywhere close to being finished, abandoned.
14:26:35FromDiscord<voidwalker> Then somebody else decides to do that same project as well, and it also gets nowhere : D
14:27:30FromDiscord<ringabout> cs.github.com is convenient too.
14:27:45FromDiscord<ringabout> https://cs.github.com/?q=%22import+binarylang%22+language%3ANim
14:39:10*rockcavera joined #nim
14:40:39*qwestion joined #nim
14:42:06FromDiscord<Phil> In reply to @xoich (xoich) "I think nim-result is": Note that this may run into the issue that you can only specify 1 return type or you'll find yourself defining a bunch of tuples or object types to specify the permutation of result + possible exceptions for the return type
14:43:59FromDiscord<Phil> (edit) "In reply to @xoich (xoich) "I think nim-result is": Note that this may run into the issue that you can only specify 1 ... returnalongside" added "error type to" | "type" => "alongside your actual return.↵That" | removed "result +" | "the return type" => "a given proc"
14:45:12FromDiscord<Phil> I guess you can also return an Object variant containing either the actual result or the exceptions, but damn that's a lot of typing
14:46:19FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4kaK
14:47:02FromDiscord<voidwalker> oh you mean it should be possible to return two errors at the same time, I understand now
14:47:22FromDiscord<Phil> Not even that, naturally you can also use enums but that loses you all previous information
14:47:32FromDiscord<Phil> (edit) "Not even that, naturally you can also use enums but that loses you all previous information ... " added "associated with the actual exception"
14:48:04FromDiscord<Phil> So if your caller decides that it's the right move to log that exception, well good luck
14:48:07FromDiscord<voidwalker> I did not consider this would be ever needed. I was just going through this lib as well contemplating how/if I could use it for my torrent project
14:48:48FromDiscord<Phil> In reply to @voidwalker "I did not consider": Accessing exception information is one of the first usecases I think of whenever Results come into play as often times I want to log them
14:50:20FromDiscord<⚶ Zeno> sent a code paste, see https://play.nim-lang.org/#ix=4kaM
14:50:45FromDiscord<Phil> That's why enums aren't truly an option in my opinion. I want that exception object. ↵And that you only get if you start playing around with the error-type being either an object, a tuple or you just return an object variant in the first place
14:51:49FromDiscord<Phil> In reply to @⚶ Zeno "hello people, how can": if the object itself is mutable, any of its fields are mutable.↵That is, assuming they're accessible.↵You can hide an object's field by not exporting them. If you want to make it readable but not writable to outside of its module, then just don't export the field, but provide a "getter" to the property
14:52:20FromDiscord<Bung> `var int` is invalid in this context
14:52:55FromDiscord<voidwalker> I guess the object fields inherit the mutability of the object variable
14:53:16FromDiscord<⚶ Zeno> In reply to @Isofruit "if the object itself": so how can i make object mutable ?
14:53:25FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4kaO
14:53:31FromDiscord<Phil> In reply to @⚶ Zeno "so how can i": `var x = A()`↵X is mutable now
14:53:34FromDiscord<Phil> (edit) "A()`↵X" => "A()`↵x"
14:53:41FromDiscord<Bung> it's mutable depends how you use it
14:54:05FromDiscord<Phil> sent a code paste, see https://paste.rs/2dp
14:54:58FromDiscord<⚶ Zeno> hold on a second, i will upload images
14:55:13FromDiscord<⚶ Zeno> https://media.discordapp.net/attachments/371759389889003532/1059485016146595840/image.png
14:55:24FromDiscord<⚶ Zeno> (edit) "hold on a second, i will upload images ... " added "(2 of them)"
14:55:27FromDiscord<⚶ Zeno> https://media.discordapp.net/attachments/371759389889003532/1059485075667955732/image.png
14:55:43FromDiscord<Phil> sent a code paste, see https://paste.rs/WY9
14:55:53FromDiscord<⚶ Zeno> yea thats what i want
14:56:06FromDiscord<Bung> so send(node: var Node)
14:56:29FromDiscord<⚶ Zeno> ooh i forgot about that
14:56:54FromDiscord<⚶ Zeno> yeah that fixes the error now, thanks !
14:57:05FromDiscord<Phil> I highly recommend playing around with that.↵It should copy every reassignment with non-ref types, but I always need to write myself mini-examples to double-check the compilers behaviour there
14:59:24FromDiscord<Phil> Generally, I find its somewhat rough to figure out in nim when it copies and when it doesn't, haven't quite gotten a feel for that yet.↵Though I also fundamentally avoid mutation nowadays, particularly in my nim-code, so I guess that explains why I haven't developed a good feel for it yet.
14:59:45FromDiscord<⚶ Zeno> understandable
15:06:49FromDiscord<Require Support> getting this weird segfault with orc, everytime i run my program i get a different stack trace. I'm not using async or threading. Any idea how I can get to the root problem? running on windows
15:07:40FromDiscord<Require Support> without orc, it works fine
15:09:08*PMunch quit (Quit: Leaving)
15:10:37FromDiscord<luteva> sent a code paste, see https://paste.rs/YAW
15:11:10FromDiscord<luteva> (edit) "https://play.nim-lang.org/#ix=4kb0" => "https://paste.rs/5VL"
15:11:47FromDiscord<luteva> (edit) "https://play.nim-lang.org/#ix=4kb2" => "https://play.nim-lang.org/#ix=4kb1"
15:26:12FromDiscord<Phil> In reply to @luteva "is there an easy": This is an example of a pragma annotation.↵To read in pragmas, you want to to use "getCustomPragmaVal" and the like, that stuff should be in....errrr let me check...
15:26:50FromDiscord<Phil> std/typetraits
15:30:08FromDiscord<Phil> sent a long message, see http://ix.io/4kb9
15:30:42FromDiscord<Phil> Nimibook docs from snorlogue about that pragma thingy:↵https://philippmdoerner.github.io/Snorlogue/bookCompiled/fileFields.html
15:34:25*arkurious joined #nim
15:40:16FromDiscord<luteva> @Phil so, in that case:↵hasCustomPragma(dummyValue, subdir)↵the subdir is the pragma and the dummyvalue is the directory, right? Or what is the "dummyvalue"?
15:41:52FromDiscord<ambient> sent a code paste, see https://play.nim-lang.org/#ix=4kbg
15:41:59FromDiscord<ambient> (I do not want every tuple (int, int) be Coord2D)
15:42:59FromDiscord<Phil> In reply to @luteva "<@180601887916163073> so, in that": That is the field that is annotated with the subdir pragma.↵Keep in mind in that code I am iterating over the fields of the type in an unrolled for-loop, so after the compiler is done with this, the code that stands there more correctly is `hascustomPragma(T()[].someField, subdir)`
15:43:38FromDiscord<Phil> with "someField" being whatever specific field fulfilled the conditions to get down to this specific piece of code
15:44:23FromDiscord<Phil> So could also be expressed as `hasCustomPragma(compileTimeInstance.myField, <pragma-name>)`
15:44:49FromDiscord<luteva> not an _easy_ (but complete) example.... 😜
15:45:21FromDiscord<luteva> but nevermind i'm gonna get it... 🙂
15:45:27FromDiscord<Phil> Okay fair, but I'm at work and that was the fastest I could do without being able to quickly compile nim code
15:45:35FromDiscord<Phil> ^^
15:46:20FromDiscord<Phil> Yeah, hopefully that gives you a bit of a better idea.↵Generally this kind of stuff all acts at compile-time and I see it mostly used when doing meta-programming that involves iterating over all fields on a type
15:46:36FromDiscord<ambient> sent a code paste, see https://play.nim-lang.org/#ix=4kbi
15:47:02FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4kbj
15:48:06FromDiscord<Phil> They are there to make writing code easier because writing `type ActionProc = proc(x: int, y: string, z: float): 0..2` and then using ActionProc everywhere is easier on the eyes than actually writing the proc definition everywhere
15:48:26FromDiscord<Phil> For making stuff explicitly different you got distinct
15:50:56FromDiscord<ambient> sent a code paste, see https://paste.rs/yUi
15:51:04FromDiscord<ambient> seq[(int, int)]
15:51:25FromDiscord<voidwalker> sent a code paste, see https://paste.rs/gUE
15:51:37FromDiscord<voidwalker> `'params' is of type <openArray[(string, string)]> which cannot be captured as it would violate memory safety,`
15:52:45FromDiscord<Phil> In reply to @ambient "It just causes this": I'd need to see the code there
15:53:18FromDiscord<ambient> sent a code paste, see https://play.nim-lang.org/#ix=4kbm
15:53:55FromDiscord<ambient> The error is in the part 1 line
15:57:47FromDiscord<Phil> Alrighty, off work so lets dive into this
15:58:23FromDiscord<Phil> How exactly do you get the aoc thingy?
15:58:32FromDiscord<Phil> I know its advent of code, I just never did advent of code
15:58:35FromDiscord<ambient> In reply to @Isofruit "I know its advent": https://github.com/amb/aoc2022/blob/master/aoc_logic.nim
16:00:18FromDiscord<voidwalker> that guy really likes aoc
16:00:32FromDiscord<ambient> It's a pretty fun way to learn a language
16:03:02FromDiscord<Phil> I don't get this repo
16:03:17FromDiscord<Phil> So what, I copy the aoc file, include it and that's it?
16:03:22FromDiscord<Phil> How do you know what your lines are?
16:03:30FromDiscord<ambient> aoc & aoc_logic
16:04:16FromDiscord<ambient> lines is in the day template
16:04:44FromDiscord<Phil> So I need to install the entire repo, not just copy-paste the files?
16:05:22FromDiscord<Phil> Wait, those are solutions, ugh
16:05:25FromDiscord<ambient> well I didn't expect that to be required, it's WIP
16:06:44FromDiscord<Phil> Could you give me the lines without the entire aoc stuff surrounding it so I can have a nicer minimal example?
16:06:56FromDiscord<Phil> Basically just defines the "lines" variable with an example input
16:07:02FromDiscord<ambient> I'll try and see if I can just write a simple test case
16:12:24FromDiscord<Phil> sent a code paste, see https://play.nim-lang.org/#ix=4kbr
16:12:53FromDiscord<Phil> Just added casting the `char` types to `int` in order to do math as there are no `-` operators defined for cha, that's pretty much it
16:13:40FromDiscord<ambient> Yeah a simpler program works fine, I don't know what exactly is going wrong. Might be something to do with the templates
16:14:19FromDiscord<ambient> https://play.nim-lang.org/#ix=4kbt
16:14:45FromDiscord<Phil> In that case I'm out, given my lack of knowledge of aoc this seems more of a custom code kind of issue
16:15:18FromDiscord<ambient> well the templates are quite straight forward and just exist as an attempt to make the code cleaner and the ability to batch run the days
16:19:37FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4kbv
16:20:14FromDiscord<Bung> echo @params.len
16:25:22FromDiscord<voidwalker> that didn't do it @Bung `proc `@`[T](a: openArray[T]): seq[T]`
16:26:28FromDiscord<voidwalker> sent a code paste, see https://play.nim-lang.org/#ix=4kby
16:27:23FromDiscord<Bung> no idea, I never discard async proc
16:28:22FromDiscord<voidwalker> I just put it there to reproduce the code context I had the error in the first plac
16:28:27FromDiscord<voidwalker> (edit) "plac" => "place"
16:30:03FromDiscord<voidwalker> oh wait righg, that's a bad example for async indeed.. wait
16:30:08FromDiscord<voidwalker> (edit) "righg," => "right,"
16:30:49FromDiscord<ambient> sent a code paste, see https://play.nim-lang.org/#ix=
16:31:07FromDiscord<voidwalker> sent a code paste, see https://paste.rs/UWL
16:32:23FromDiscord<ambient> -d:nimNoLentIterators solves my issue, but I'm still unsure what is exactly the cause
16:32:33FromDiscord<voidwalker> well, it is async related, no async and it compiles
16:35:42FromDiscord<Bung> oh , I see "Procedures marked {.async.} do not support mutable parameters such↵## as `var int`. References such as `ref int` should be used instead."
16:36:37FromDiscord<voidwalker> but what is var here ?
16:36:55FromDiscord<Bung> hidden pointer
16:38:07FromDiscord<voidwalker> right, so I have to give up on openArray or is there a workaround ?
16:38:23FromDiscord<voidwalker> I don't really need openArray, but now I am curious to understand what is going on
16:39:18FromDiscord<Bung> so use generic with seq[string]| tuple[string,string]
16:39:27FromDiscord<Bung> (edit) "seq[string]|" => "seq[string] |"
16:40:57FromDiscord<voidwalker> haha ok, as I don't really need it, I will stick with seq : P
16:41:04FromDiscord<Bung> (edit) "so use generic with seq[string] | tuple[string,string] ... " added "for example, I dont know what types you wanna input"
16:41:39FromDiscord<voidwalker> actually I might need it...
16:42:00FromDiscord<voidwalker> I want array[n, (string, string)] or seq[(string, string)].. thus the openArray
16:43:14FromDiscord<Crews> Hello! I'm an F# developer looking to do more systems-level programming. F# has Algebraic Data Types, which include Unions/Discriminated Unions.↵↵Are there good examples of how Nim solves the problem of having a type that could be one of several types?
16:46:21FromDiscord<Bung> generic and typeclass
16:46:35FromDiscord<Rika> Nim has a more funky working kind of discriminated union
16:52:45FromDiscord<Crews> In reply to @Rika "Nim has a more": Could you elaborate?
16:54:40FromDiscord<Rika> Better to just see this https://nim-lang.org/docs/manual.html#types-object-variants
16:58:13FromDiscord<voidwalker> aren't concepts better suited for this kind of modeling /
16:58:26FromDiscord<voidwalker> I don't know much about it, but found this post: https://github.com/nim-lang/RFCs/issues/5#issuecomment-649596198
16:58:28FromDiscord<Rika> Depends
16:59:24FromDiscord<Rika> Concepts of course still don’t allow for heterogeneous containers
17:00:08FromDiscord<Rika> Of course object variants only emulate it but concepts wouldn’t help at all I think
17:04:28FromDiscord<jtv> Your concrete type w concepts can be a discriminated union and you can effectively do the type casing at compile time
17:04:43FromDiscord<Crews> sent a code paste, see https://play.nim-lang.org/#ix=4kbH
17:05:00FromDiscord<Crews> In reply to @jtv "Your concrete type w": Do you have a link to an example of that?
17:08:01*nmz joined #nim
17:16:42FromDiscord<ShalokShalom> @Crews There are macros, who let it look like DUs↵↵Fellow FSharper here
17:17:16FromDiscord<ShalokShalom> https://github.com/andreaferretti/patty#constructing-variant-objects
17:17:25FromDiscord<ShalokShalom> Thats a pattern matching library
17:17:34FromDiscord<ShalokShalom> That also supports DUs.
17:18:08FromDiscord<Crews> In reply to @ShalokShalom "<@822242039437066280> There are macros,": Yeah, I love F#, but I've been pushing the performance and Nim seems like a nice next step. I'd rather not work in raw C 🤣
17:18:51FromDiscord<ShalokShalom> F# and Nim are surprisingly similar
17:19:50*pro joined #nim
17:19:58FromDiscord<ShalokShalom> https://github.com/ringabout/awesome-nim#functional-programming
17:20:02FromDiscord<Crews> In reply to @ShalokShalom "F# and Nim are": Yes! They feel like cousin languages even though F# comes from the ML family and Nim is apparently from more of the Python line
17:20:22FromDiscord<ShalokShalom> Nim often does not know, that it's functional, when it is. ↵↵Take this list, as an example.
17:20:45FromDiscord<ShalokShalom> In reply to @Crews "Yes! They feel like": Nim is actually an Oberon/Pascal like language
17:21:06FromDiscord<Crews> In reply to @ShalokShalom "Nim is actually an": Don't know Oberon. Have to look it up...
17:21:08FromDiscord<ShalokShalom> It's syntax just looks like Python and there are many useful Python related libraries
17:21:26FromDiscord<ShalokShalom> Like Nimpy, that lets you use Python libraries
17:22:01FromDiscord<wiga> Any way to compress data with staticRead and compress it on compile time?
17:23:05FromDiscord<wiga> I have tried using zippy gzip compression but doesn't work on compile time
17:43:16FromDiscord<luteva> how can i get all types of a module?
17:46:38FromDiscord<luteva> sent a code paste, see https://play.nim-lang.org/#ix=4kbX
17:49:25FromDiscord<luteva> sent a long message, see http://ix.io/4kbY
17:54:38FromDiscord<luteva> or do i totally misunderstand how this should be used?
17:57:13FromDiscord<Elegantbeef> sent a code paste, see https://paste.rs/r6C
18:00:05FromDiscord<luteva> ok this is by using a concept..... so this is probably the easiest way?!?↵Would it be possible to get all types of a module and check if the type uses the pragma? (just for learning)
18:00:22FromDiscord<Elegantbeef> Nope
18:00:28FromDiscord<luteva> ok thx.
18:00:33FromDiscord<Elegantbeef> You cannot query a module for symbols without hacks
18:00:40FromDiscord<luteva> ok
18:10:38FromDiscord<Entikan> Anyone have an idea how I can pre-compile a set of nim modules to be imported by another nim project?
18:10:49FromDiscord<Entikan> would save me a lot of compile time
18:11:09FromDiscord<Entikan> --incremental:on doesn't seem to work for me, probably because it is at an experimental state.
18:12:44FromDiscord<Entikan> I'm not experienced enough with nim to narrow down my problem with --incremental
18:13:41FromDiscord<Entikan> I want to use a pretty big set of bindings but it's taking so long to compile now
18:16:50FromDiscord<Elegantbeef> There isnt much of a way to do that as of yet
18:19:44FromDiscord<⚶ Zeno> how can i solve "of type <var ....> which cannot be captured as it would violate memory safety" errors ?
18:19:55FromDiscord<Elegantbeef> Depends
18:19:59FromDiscord<Elegantbeef> You can copy the variable
18:20:09FromDiscord<⚶ Zeno> i do need the original variable itself though
18:20:09FromDiscord<Elegantbeef> Or pass in a reference without `var`
18:20:12FromDiscord<emanresu3> Hi, any recommendations for an xml parser and web requests? are the one in standard library good enough (httpclient, parsexml)?
18:20:17FromDiscord<⚶ Zeno> im reassigning attributes of it
18:20:30FromDiscord<⚶ Zeno> https://media.discordapp.net/attachments/371759389889003532/1059536681042198608/image.png
18:20:32FromDiscord<Elegantbeef> Well then change the object to a reference
18:20:36FromDiscord<Elegantbeef> and pass it in without var
18:20:40FromDiscord<⚶ Zeno> alright, thanks
18:21:27FromDiscord<Elegantbeef> Technically if you know it's safe to you can copy the address to a local variable and access that, but that's unsafe nim
18:24:19FromDiscord<⚶ Zeno> In reply to @Elegantbeef "and pass it in": well im dumb, can you give quick example ?
18:24:49FromDiscord<⚶ Zeno> sent a code paste, see https://play.nim-lang.org/#ix=4kc5
18:25:03FromDiscord<⚶ Zeno> and when you say "pass it in without var", i understand it as just keep type of parameters as "Node"
18:25:10FromDiscord<⚶ Zeno> and now i get this https://media.discordapp.net/attachments/371759389889003532/1059537854549733416/image.png
18:25:38FromDiscord<⚶ Zeno> (ask if you want full error, but i think thats enough picture ?)
18:25:49FromDiscord<Elegantbeef> sent a code paste, see https://play.nim-lang.org/#ix=4kc6
18:25:58FromDiscord<⚶ Zeno> (edit) "https://play.nim-lang.org/#ix=4kc5" => "https://play.nim-lang.org/#ix=4kc7"
18:26:01FromDiscord<Elegantbeef> The issue is now with `ref` you need to explicitly allocate either doing `new MyObject` or `MyObject(...)`
18:26:10FromDiscord<Elegantbeef> It's a heap allocated type now
18:27:23FromDiscord<Require Support> stack traces when using libraries with orc 💀 you never know what is going wrong
18:27:58FromDiscord<⚶ Zeno> In reply to @Elegantbeef "The issue is now": oh that is fine
18:28:05FromDiscord<⚶ Zeno> anyway thanks a lot, now it works
18:28:15FromDiscord<⚶ Zeno> i just didnt know i had to do `new ...` or `...()`
18:28:52FromDiscord<⚶ Zeno> (edit) "In reply to @Elegantbeef "The issue is now": oh that is fine ... " added "(for me)"
18:29:10FromDiscord<Elegantbeef> The issue with var and closures is that the variable could be on the stack which means you can have a dangling pointer
18:29:17FromDiscord<Crews> What editor/IDE do people recommend for Nim development?
18:29:20FromDiscord<Elegantbeef> Just to explain why
18:29:24FromDiscord<⚶ Zeno> i see
18:29:46*wallabra joined #nim
18:29:46FromDiscord<⚶ Zeno> In reply to @Crews "What editor/IDE do people": thats personal opinion, but for my case i use nim, i also saw ppl use neovim
18:29:49FromDiscord<⚶ Zeno> use whatever ur comfortable with
18:29:58FromDiscord<⚶ Zeno> (edit) "nim," => "VSC,"
18:30:20FromDiscord<Crews> In reply to @⚶ Zeno "thats personal opinion, but": Extension you recommend? I see a couple
18:30:51FromDiscord<⚶ Zeno> nimsaem:Nim↵and code runner if ur too lazy to do `nim c -r ...` repeatedly
18:32:54FromDiscord<ShalokShalom> In reply to @Crews "Extension you recommend? I": If it does make issues to you:↵↵https://discord.com/channels/371759389889003530/371759389889003532/1054117863125958716
18:33:16FromDiscord<ShalokShalom> There is also a Jetbrains implementation
18:33:26FromDiscord<ShalokShalom> That's different, implementation wise
18:33:54FromDiscord<Elegantbeef> There's an LSP and it's all backed by nimsuggest so the experience is pretty much the same everywhere
18:33:54FromDiscord<Elegantbeef> I personally use kate + nimlsp
18:34:00FromDiscord<ShalokShalom> Otherwise, all besides the IntelliJ one depend on the compiler-own "nimsuggest"
18:34:33FromDiscord<Crews> I have the JetBrains suite so I guess I'll try that as well
18:34:53FromDiscord<Elegantbeef> The jetbrains extension is much simpler than nimsuggest
18:35:34FromDiscord<Elegantbeef> It doesnt compile the code so templates/macros that add symbols will not be visible
18:45:07*pro quit (Quit: pro)
18:45:33FromDiscord<jtv> @Crews Sorry I went into a lunch, did you figure out how to do what you want to do?
19:09:10FromDiscord<4zv4l> I have a question about a nim program, I would understand if it's not appropriate to answer or send the code↵basically last year I had to make a ransomware in C using openssl aes encryption↵I tried making one in Nim which I thought were working (on an filesystem I made myself) but my colleague sent me the teacher's test filesystem and when I decrypted I didn't get the same checksum (sha256)↵can I share the code to get why ?
19:12:38FromDiscord<voidwalker> Are you kidnapped and force to code ransomware?
19:12:46FromDiscord<voidwalker> (edit) "force" => "forced"
19:13:06FromDiscord<voidwalker> (edit) "Are you kidnapped and forced to code ransomware? ... " added "Or what do you mean by "I had to""
19:13:32FromDiscord<voidwalker> Or had to like a school assignment
19:13:35FromDiscord<4zv4l> lmao I am not↵I just wanna understand why the decryption sometimes works and sometimes does not↵↵oh "had to" because last year I had to, to get my grade
19:13:40FromDiscord<4zv4l> that was our exam
19:14:25FromDiscord<voidwalker> So you want your homework done, ok
19:14:30FromDiscord<4zv4l> ||https://github.com/4zv4l/ransomware||
19:14:31FromDiscord<4zv4l> no no
19:14:34FromDiscord<4zv4l> I made it already last year
19:14:38FromDiscord<4zv4l> now I am making it in Nim
19:14:40FromDiscord<4zv4l> to try
19:15:19FromDiscord<4zv4l> and I thought it was working until my mate sent me a folder containing random files↵and when I the content wasn't the same as before
19:15:21*derpydoo joined #nim
19:15:27FromDiscord<4zv4l> just wanna know why↵if I can ask
19:16:18FromDiscord<voidwalker> well that's a completely meaningless question without code context
19:16:53FromDiscord<4zv4l> that's why I asked if I can send it xD
19:16:56FromDiscord<voidwalker> you seem experienced enough to debug it to a point where you can see what bytes get hashed, to know why it fails
19:17:42FromDiscord<4zv4l> well I use a lib `nimAES` which seems a bit weird to use with aes CTR
19:18:05FromDiscord<jtv> Still, if two checksums aren't the same, then the two inputs aren't the same.
19:18:35FromDiscord<jtv> So do the work to figure out where the inputs are different and why, and if there's something that doesn't make sense about it, then perhaps we can help
19:19:01FromDiscord<4zv4l> well the `why` is why I am here
19:19:16FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=4kcm
19:19:27FromDiscord<jtv> "weird to use with CTR" is surprising. If it has a raw AES encrypt of an openarray[16, byte] it should be easy to implement counter mode yourself
19:19:36FromDiscord<4zv4l> it works just fine with hand made files
19:19:48FromDiscord<4zv4l> but I guess there are exception which is what I try to understand
19:21:38FromDiscord<jtv> Why are you using AES-CTR instead of something like AES-GCM, which will at least help you detect when the ciphertext is invalid for some reason??
19:24:14FromDiscord<jtv> But nothing above is going to make it easy for us to help you... there's not enough context for us. Like @voidwalker said, you should be able to figure out where the problem is a lot more specifically, i.e., where exactly you end up w/ 2 strings that don't match. And at that point, you'll hopefully be able to generate a much more specific question, because otherwise it's not much better than "please debug my code".
19:26:04FromDiscord<4zv4l> In reply to @jtv "Why are you using": because there isn't in Nim AES I think
19:26:04FromDiscord<4zv4l> https://github.com/jangko/nimAES
19:26:19FromDiscord<4zv4l> I saw it's using stream so easier to use
19:26:31FromDiscord<jtv> Then I'd use a different library, because that's just rubbish
19:26:33FromDiscord<4zv4l> "easier" in the way that I can just pass it the content of the file
19:26:53FromDiscord<4zv4l> In reply to @jtv "Then I'd use a": do you have a good one ?
19:26:57FromDiscord<jtv> Same thing w/ any good GCM implementation. GCM is just CTR-mode for encryption, but a fast integrity check as part of it
19:27:19FromDiscord<jtv> Well, it's the default cipher suite for TLS, so I'm sure it's already buried in Nim's wrapping of OpenSSL
19:28:09FromDiscord<jtv> But anything that is going to give you a bunch of modes no cryptographer would use on its own anymore (or at all in the case of things like OFB, CFB, etc) is a toy project at best.
19:28:34FromDiscord<jtv> That library looks like it was built by someone who was excited to read Applied Cryptography, even though it's about 30 years old.
19:29:57FromDiscord<jtv> A quick search turns up nimcrypto, which I know gets used in a number of projects, and here's their GCM example: https://github.com/cheatfate/nimcrypto/blob/master/examples/gcm.nim
19:31:16FromDiscord<jtv> I have no clue if that would be leveraging underlying hardware support for GCM though, whereas OpenSSL definitely would, but is probably vastly underdocumented (openssl is complex, and the nim wrapping isn't well documented)
19:31:48FromDiscord<federico3> or you can use libsodium instead
19:33:47FromDiscord<jtv> Sure, that works too, though I was an author of GCM, so I'm contractually obliged to push it 😉
19:34:50FromDiscord<4zv4l> yeah I'm taking a look a nimcrypto ^^↵thanks !
19:35:08*jmdaemon joined #nim
19:35:16FromDiscord<jtv> I suspect if you make that switch your problem might go away, and if not, you should be able to pin down where it's failing more easil
19:35:22FromDiscord<jtv> At which point we can be more helpful
19:47:15FromDiscord<4zv4l> seems to work for now↵gonna try with the filesystem that made my previous code not working that well https://media.discordapp.net/attachments/371759389889003532/1059558507558469843/image.png
19:52:25FromDiscord<jtv> Cool
19:55:00FromDiscord<4zv4l> https://media.discordapp.net/attachments/371759389889003532/1059560463886725170/image.png
19:55:04FromDiscord<4zv4l> well so yeah↵some files are ok
19:55:07FromDiscord<4zv4l> some are not
19:56:06FromDiscord<4zv4l> sent a long message, see http://ix.io/4kcz
19:56:07FromDiscord<4zv4l> 3 files changed
19:56:38FromDiscord<jtv> Yeah, so you need to figure out where the input strings that you're passing in are differing.
19:57:20FromDiscord<jtv> GCM should be telling you whether decryption fails or not too. If the library has a mode where you can ignore that, it's not to spec, definitely make sure to test that
19:57:38FromDiscord<jtv> Because it shouldn't be the case that you COULD decrypt it without getting back what was put in
20:01:36FromDiscord<Entikan> In reply to @Elegantbeef "There isnt much of": well that sucks
20:02:14FromDiscord<Entikan> so much for efficiency
20:02:30FromDiscord<Entikan> I thought that was top priority
20:03:29FromDiscord<jtv> They're working on incremental compilation, but the "efficiency" is in compile time, not run time, so I'm surprised that's why you'd have issue w/ it?
20:04:16FromDiscord<Entikan> yeah me too to be honest
20:05:53FromDiscord<Entikan> the complexity is coming from these bindings: https://github.com/rdb/nim-panda3d
20:05:59FromDiscord<Entikan> perhaps it's doing something?
20:06:39FromDiscord<Entikan> it it because core.nim is one huge file
20:07:23FromDiscord<Entikan> (edit) "it" => "is" | "core.nim" => "panda3d/core.nim" | "file" => "file?"
20:11:09FromDiscord<jtv> I mean, if you're worried about compile time, without incremental compilation, breaking it up into smaller files isn't going to speed things up
20:11:26FromDiscord<jtv> You can generate a so and dynamically load it if you want??
20:12:02FromDiscord<Entikan> that sounds nice. Can I just import so as if any nim module?
20:13:32FromDiscord<Entikan> In reply to @jtv "I mean, if you're": Yeah I figured. But Very Large Files is also something a lot of software seem to have quirks with.
20:13:54FromDiscord<Entikan> (edit) "In reply to @jtv "I mean, if you're": Yeah I figured. But ... Very" added "dealing with"
20:16:23FromDiscord<jtv> No, I would expect you have to call their wrapped dlopen(), and I don't know the flag magic to output a so yet, either.
20:16:34FromDiscord<jtv> But I've seen the wrapped dlopen() when looking through source
20:17:46FromDiscord<jtv> And while I assume there's a flag for .so output, it's definitely doable since you can target C output, then just control the link line yourself.
20:18:29FromDiscord<Elegantbeef> `--app:lib`
20:18:35FromDiscord<Entikan> I've made an so on accident with --app:lib
20:18:36FromDiscord<Entikan> yeah
20:18:50FromDiscord<Entikan> not sure what dlopen() is though (I come from python)
20:19:11FromDiscord<Elegantbeef> It's how one opens a dynamic linked library
20:19:38FromDiscord<Elegantbeef> The panda bindings iirc are needlessly complex
20:19:54FromDiscord<Entikan> In reply to @Elegantbeef "The panda bindings iirc": how so?
20:20:10FromDiscord<Elegantbeef> image.png https://media.discordapp.net/attachments/371759389889003532/1059566796870529124/image.png
20:20:15FromDiscord<Entikan> note panda3d != pandas
20:20:46FromDiscord<Entikan> ah
20:20:47FromDiscord<jtv> The dlopen() interface is pretty straightforward though; man dlopen will give you the C version nim wraps
20:21:04FromDiscord<Entikan> I'll look into dlopen(), thanks!
20:21:10FromDiscord<Elegantbeef> They also have `init` procedures for 0'd types
20:21:11FromDiscord<Elegantbeef> Nim automatically zeros
20:21:42FromDiscord<Entikan> oh interesting
20:22:08FromDiscord<Elegantbeef> image.png https://media.discordapp.net/attachments/371759389889003532/1059567289478942830/image.png
20:22:11FromDiscord<Elegantbeef> These could also just be a generic
20:22:13FromDiscord<Entikan> @ElegantBeef I don't suppose you could file a few issues about this >.<
20:22:27FromDiscord<Entikan> you'd be doing me a pretty huge favor
20:23:20FromDiscord<Elegantbeef> I think the author was already here and i mentioned using a dotoperator macro for the swizzling
20:24:25FromDiscord<Entikan> oh cool
20:24:39FromDiscord<4zv4l> sent a code paste, see https://paste.rs/kTm
20:26:55FromDiscord<4zv4l> all the checksum are wrong now
20:27:15FromDiscord<4zv4l> oh wait
20:27:19FromDiscord<4zv4l> no, same files as before
20:27:29*krux02_ joined #nim
20:28:14FromDiscord<jtv> The AAD is irrelevant, you can 100% skip it.
20:28:46FromDiscord<jtv> And the decryption definitely fails and does nothing if you change a random byte?
20:28:51FromDiscord<4zv4l> In reply to @jtv "The AAD is irrelevant,": did I skip it the right way ?
20:29:27FromDiscord<jtv> You don't need to provide it. It's just assumed to be an empty string if it doesn't exist. I guess the API could require it but I'd doubt it
20:29:29FromDiscord<4zv4l> In reply to @jtv "And the decryption definitely": what do you mean ? some files succeeded to be decrypted
20:29:38FromDiscord<4zv4l> In reply to @jtv "You don't need to": it requires it
20:30:29FromDiscord<jtv> Weird, that API makes you rekey every time you want toc change the nonce??
20:30:57FromDiscord<jtv> I'd assume there's some sort of rekey function
20:31:44FromDiscord<jtv> Honestly, if I were designing it, I'd probably just use a hash of the file name truncated to 12 bytes as the nonce (12 bytes is a special maximally efficient size for GCM)
20:32:15FromDiscord<jtv> But each file should get its own nonce.
20:32:22FromDiscord<jtv> Still, I don't think that's likely to be your problem
20:32:44FromDiscord<4zv4l> yeah I really don't see why it works on some files and on some others doesn't
20:34:30FromDiscord<jtv> So the length of the ciphertext is 16 bytes LONGER than the plaintext
20:34:42FromDiscord<jtv> Because of the integrity check
20:35:40FromDiscord<Elegantbeef> @Entikan\: there you go i made an issue, you can either implement the changes or await the maintainer 😛
20:35:48FromDiscord<jtv> So could be some low-level issue where you're essentially potentially getting some extra bytes in the output that should not be there, IDK
20:36:14FromDiscord<jtv> Spot check doesn't show any other big reasons. If this were C, the most likely culprit would be the file being opened in text mode
20:36:51FromDiscord<jtv> But I'm pretty sure Nim always does binary with the standard file APIs
20:38:14FromDiscord<4zv4l> In reply to @jtv "So the length of": I tried adding the size change but then no file was decrypted correctly
20:40:53FromDiscord<Entikan> In reply to @Elegantbeef "<@716041936758374501>\: there you go": thank you so much!!! <3<3<3
20:41:21FromDiscord<jtv> Well, when you don't do that, do the files get written to the correct length? The output file will be 16 bytes longer than the input file
20:42:03FromDiscord<jtv> And when decryption fails, would be nice to know whether the sizes are the same, and whether the contents LOOK decrypted
20:46:37FromDiscord<<She>Horizon</Her>> What does the inline pragma do in Nim?
20:46:56FromDiscord<4zv4l> https://media.discordapp.net/attachments/371759389889003532/1059573529143672892/image.png
20:46:59FromDiscord<4zv4l> yeah it keeps the same size
20:47:23FromDiscord<4zv4l> but the content afterwards is not good good
20:49:12FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=4kcY
20:50:19FromDiscord<jtv> Well I can promise you GCM's correct output is 16 bytes longer than the input
20:50:43FromDiscord<jtv> So they're probably doing the dumb thing where they separate the authentication information which is explicitly NOT allowed in the spec
20:51:12FromDiscord<voidwalker> So the teachers are buggy ?
20:51:57FromDiscord<jtv> Oh yeah, it's there in their code, they separate out the last 16 bytes into a "tag" field, which is again a horrible idea
20:52:25FromDiscord<jtv> There 100% should be an API call to check the tag before returning any decrypted value
20:52:51FromDiscord<jtv> By spec, those 16 bytes are supposed to be the last 16 bytes of the ciphertext
20:54:17FromDiscord<jtv> But even so, you're still at the point where SOMETHING is different, and you should inspect the actual contents to see which bytes are decrypting and which ones aren't
20:56:11FromDiscord<4zv4l> like this ?
20:56:13FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=4kd0
20:56:21FromDiscord<4zv4l> (edit) "https://paste.rs/Vsz" => "https://play.nim-lang.org/#ix=4kd1"
20:57:40FromDiscord<jtv> Yeah, so that tells me you aren't passing the same state off.
20:57:45FromDiscord<jtv> Here's what I think is happening
20:59:44FromDiscord<jtv> sent a long message, see http://ix.io/4kd2
20:59:47FromDiscord<jtv> Or something along those lines.
21:00:37FromDiscord<4zv4l> I should create a new context for each file ?
21:00:40FromDiscord<jtv> Giving each file a unique nonce allows you to also decrypt one file at a time
21:00:43FromDiscord<4zv4l> would that be a solution ?
21:01:05FromDiscord<jtv> Well, like I said, the library should absolutely give you a way to change the nonce and AAD WITHOUT having to rekey AES (which is relatively expensive)
21:02:07FromDiscord<jtv> So for each file, I'd set up a new nonce, and the nonce would be the SHA-256 of a string consisting of a file name concatenated with the file length, truncating the SHA-256 output to 12 bytes.
21:05:11FromDiscord<4zv4l> oh
21:05:12FromDiscord<4zv4l> it works
21:05:28FromDiscord<4zv4l> that was indeed the renew of the nonce which made the order of the files important
21:06:33FromDiscord<jtv> Good to hear
21:06:42*derpydoo quit (Ping timeout: 252 seconds)
21:07:15FromDiscord<jtv> The way your code was before, the problem was NOT renewing the nonce, and having the file order change due to the hash order changing 🙂
21:07:29FromDiscord<jtv> Glad we got it sorted, though
21:08:44FromDiscord<4zv4l> In reply to @jtv "So for each file,": I'll try doing this now
21:12:18FromDiscord<jtv> Some of the ransomware I've seen will use a separate key for each file, then allowing the ransomware team give the victim a taste... here, we'll give you a program to unencrypt this one file, but without having to give them what they need to unencrypt everything, unless they pay.
21:13:19FromDiscord<4zv4l> well my purpose is really not to arm anyone↵I just wanted to succeed making this work in Nim
21:13:25FromDiscord<4zv4l> and finally
21:13:26FromDiscord<4zv4l> it does
21:14:01FromDiscord<jtv> Yeah, sure, but anyone who wants to build this stuff for offensive purposes isn't going to have a hard time already. hash the file name and length, then use THAT key to do the
21:14:04FromDiscord<4zv4l> In reply to @jtv "Some of the ransomware": so they need to keep track of which key has been used for which file ?
21:14:10FromDiscord<jtv> Nope
21:14:18FromDiscord<jtv> You use a similar trick
21:14:29FromDiscord<jtv> Generate one random "master" key
21:14:40FromDiscord<4zv4l> In reply to @jtv "Yeah, sure, but anyone": isn't it easy to guess ?
21:14:40FromDiscord<jtv> For each file, hash the filename and length
21:14:54FromDiscord<jtv> encrypt that value w/ the master key
21:15:11FromDiscord<4zv4l> makes sense
21:15:15FromDiscord<jtv> Then use that 256-bit encrypted hash as the key to encrypt the file
21:15:22FromDiscord<jtv> And there, you can now use 0 as a nonce for each file
21:15:45FromDiscord<jtv> Now, just from the file name and size, the bad guy can reconstruct the file key from the one master key
21:16:14FromDiscord<4zv4l> so if the people during that time change the filename↵the bad guy can't help right ?
21:16:53FromDiscord<jtv> Well, the person whose files have been decrypted is unlikely to change the file name.
21:17:18FromDiscord<jtv> But, you can keep that info in the output file
21:17:31FromDiscord<jtv> If that really matters
21:17:50FromDiscord<jtv> i.e., encrypt, then in the file write the file name, length and ciphertext (w/ tag)
21:19:01FromDiscord<jtv> That's generally how I'd do it anyway, as I'd use the full path to each file to help ensure uniqueness of nonces
21:20:20FromDiscord<4zv4l> well, that sounds really interesting↵thank you so much for your explanation and time↵I'll try doing something similar here and see if I won't break my program again xD
21:22:23FromDiscord<jtv> LOL well I'll probably be around if you run into issues
21:22:37FromDiscord<4zv4l> In reply to @jtv "But, you can keep": if you write that in the output file, won't they see those info ?
21:22:46FromDiscord<4zv4l> oh but they still don't have the master key
21:23:11FromDiscord<jtv> Sure, but they already know what the file name and file size were, it's not data you're trying to keep secret, it's just used to compute the nonce
21:23:21FromDiscord<jtv> Yeah, it's the master key that's the secret you care about
21:24:54FromDiscord<4zv4l> In reply to @jtv "Sure, but they already": they key you mean right ? you said the nonce could be 0 using that technique
21:25:11FromDiscord<4zv4l> or using master key + nonce (nonce being the filename + size in sha256)
21:27:50FromDiscord<jtv> Right, the nonce for the key generation function
21:29:03FromDiscord<jtv> So KDF(masterKey, filename, filesize) = AES(masterkey, SHA256(filename & $(filesize))
21:29:12FromDiscord<jtv> Would return you a key for that file
21:29:44FromDiscord<4zv4l> I'm sorry I didn't quite get this
21:30:36FromDiscord<jtv> So you break into a machine, you generate a random master key that you upload to your server. You use that to create a series of keys, via the above key derivation function (KDF)
21:30:40FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=4kd7
21:31:08FromDiscord<4zv4l> so masterkey is the key and sha256(filename & $filesize) is the nonce
21:31:12FromDiscord<jtv> No, you encrypt that hash with the "master" key
21:31:31FromDiscord<jtv> That's how you keep the target from being able to reverse engineer and decrypt their own stuff
21:32:02FromDiscord<jtv> Right, sha256(filename & $filesize) is the nonce to your KDF to get a key to encrypt that file with
21:32:27FromDiscord<jtv> Then that key can use 0 as a nonce, since the "requirement" is that key, nonce pairs cannot be reused
21:33:00FromDiscord<jtv> Each key is randomized and statistically going to be unique, so 0 is a perfectly fine nonce, as long as each target also has a random master key
21:35:34FromDiscord<4zv4l> In reply to @jtv "So KDF(masterKey, filename, filesize)": is there a short function to get the result of the `AES(masterkey, SHA256(filename & $filesize))` ?
21:38:48FromDiscord<jtv> Well, depends on the library, but it'd be fine to put AES in CTR mode for that
21:44:11*genpaku quit (Remote host closed the connection)
21:45:42FromDiscord<4zv4l> and for the encryption file still GCM ?
21:47:49FromDiscord<jtv> I would
21:48:40FromDiscord<jtv> Always worth knowing when your ciphertext has been mucked with
21:48:43*genpaku joined #nim
22:14:27FromDiscord<4zv4l> jeez finally https://media.discordapp.net/attachments/371759389889003532/1059595556357427220/image.png
22:14:46FromDiscord<4zv4l> https://media.discordapp.net/attachments/371759389889003532/1059595634631528488/aes.nim
22:14:50FromDiscord<4zv4l> probably not the best code but
22:14:50FromDiscord<4zv4l> jeez
22:17:50*wallabra quit (Ping timeout: 260 seconds)
22:33:49NimEventerNew thread by jtv: A seasoned programmer's take on Nim's docs, see https://forum.nim-lang.org/t/9791
22:34:07FromDiscord<jtv> Congrats 🙂
22:40:39*derpydoo joined #nim
22:41:05FromDiscord<4zv4l> sent a code paste, see https://play.nim-lang.org/#ix=4kdf
22:43:22FromDiscord<jtv> Well your master key should just be random bits, and then you use that to encrypt the hash, and as long as hash outputs never repeat you will never have an issue
22:43:30FromDiscord<jtv> Which, statistically they will not
22:44:07FromDiscord<jtv> They’d have to have the master key to be able to reconstruct generated keys
22:45:34FromDiscord<4zv4l> well thank you so much↵with you I didn't only fix my program but also improved it a lot↵thank you ^^
22:46:38*ltriant joined #nim
22:46:46FromDiscord<jtv> My pleasure
22:49:23*azimut quit (Ping timeout: 255 seconds)
23:02:03*derpydoo quit (Ping timeout: 248 seconds)
23:04:16FromDiscord<4zv4l> to send the key to the server I guess using DNS + asym enc to send it, would be the best bet ?
23:04:30FromDiscord<4zv4l> but then for the test I can't just use netcat xD
23:05:35FromDiscord<jtv> I guess, I’d probably just write to an S3 bucket and be done.
23:06:48FromDiscord<jtv> But in a real world scenario yeah you’d generally encrypt to some private key and post it somewhere
23:07:58FromDiscord<4zv4l> oh right, I should add the full path in the code rather than using the filename only↵that's in case the file has been copied somewhere else on the disk right ?
23:08:40*ehmry quit (Ping timeout: 252 seconds)
23:10:35*ehmry joined #nim
23:12:06FromDiscord<jtv> Yup
23:12:38FromDiscord<jtv> Like someone nuked that machine but wants to restore from a backup, etc
23:12:48FromDiscord<jtv> But that's encrypted 🙂
23:14:27nmzSo Nim requires 3gb to build
23:14:28FromDiscord<4zv4l> what do you mean ? if they have a backup they're good aren't they ?↵except obviously if the backup is on the server itself 🤡
23:14:40nmzmy pc just hanged, would be nice to put it somewhere in the install instructions
23:14:48nmztoypc*
23:17:12FromDiscord<jtv> If their only backup is post-encryption
23:17:53FromDiscord<jtv> Generally if someone gets on your laptop and encrypts files, IT isn't going to have you keep using that laptop, but I've seen them rebuild the laptop...
23:32:39FromDiscord<4zv4l> In reply to @jtv "If their only backup": yes right, get it
23:32:49FromDiscord<4zv4l> In reply to @jtv "Generally if someone gets": well can wipe and start over 🥺
23:32:55*wallabra joined #nim