rohitpaulk has quit [Remote host closed the connection]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
ShalokShalom has joined #crystal-lang
ShalokShalom has left #crystal-lang [#crystal-lang]
<FromGitter>
<chussenot> I spend a lot of time to write loops to parse an XML document... I don't thing that;s it's the best approach ... If someone knows an efficient library, please share it. I did not see much valuable solution in the doc, the specs or on the awesome crystal repo :|
<FromGitter>
<jwoertink> My guess is using `OpenSSL::Cipher.new("aes-256-cbc")`, but I'm not sure
<FromGitter>
<Blacksmoke16> but kinda have to build it all out on its own
<FromGitter>
<jwoertink> Yeah, that's what I'm seeing too. I'm getting different results, so I assumed I was doing something wrong
<FromGitter>
<tenebrousedge> yeah, if I recall correctly, someone working on it last week found it to be ridiculously involved
<FromGitter>
<Blacksmoke16> @dscottboggs_gitlab ^
<FromGitter>
<jwoertink> It does feel that way. Looking around in Ruby it seems to be the same
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<tenebrousedge> PHP is better than Ruby and Crystal! D:
<FromGitter>
<jwoertink> lol
alex`` has joined #crystal-lang
lucasb has joined #crystal-lang
<oprypin>
hol up
<FromGitter>
<jwoertink> ok, next one is PHP's `hash_pbkdf2("sha1", "secret", "salt", 1024, 48, false)`. I'm using `String.new(OpenSSL::PKCS5.pbkdf2_hmac_sha1("secret", "salt", 1024, 48))`
<FromGitter>
<jwoertink> In PHP I get `string(48) "2733bc2dec4604bcffd043cde0cc72f0135f95712dca20cc"`, but in crystal I get `"'3\xBC-\xECF\u0004\xBC\xFF\xD0C\xCD\xE0\xCCr\xF0\u0013_\x95q-\xCA ̡m\xA5\xFF\x9F8a\xB4m~\xCE\u0015\xC2\xFB\xD8\u007Fq\xD4\u0016\xBA\x9D\xC0"`
<FromGitter>
<jwoertink> Anyone know how I can convert this properly?
<FromGitter>
<jwoertink> The `pbkdf2_hmac_sha1` method actually returns bytes, so maybe passing to String.new is wrong here?
<FromGitter>
<kinxer> @jwoertink Is `OpenSSL::PKCS5` in stdlib?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<tenebrousedge> just seeing "UTF-16" makes me twitch. A few years back, I was writing interfaces for a few dozen mostly undocumented APIs. I got a bug report about random garbage characters in data from one source, and spent a day or two going over the code with a fine-toothed comb before realizing that the data was being returned as UTF-16 rather than UTF-8. Since then, I've had some strong opinions about API
<FromGitter>
... documentation, or the lack thereof
<FromGitter>
<z64> @jwoertink https://www.php.net/manual/en/function.hash-pbkdf2.php ⏎ "Returns a string containing the derived key as lowercase hexits unless raw_output is set to TRUE in which case the raw binary representation of the derived key is returned." ⏎ i believe crystal is giving you this (the raw binary repr), and you're comparing it to the safe lowercase hexits output
<FromGitter>
<jwoertink> @kinxer yeah it is
<FromGitter>
<kinxer> @Blacksmoke16 Is that the package that somehow dropped out of the API documentation like 6 versions ago?
<FromGitter>
<Blacksmoke16> yea, it got added back in master
<FromGitter>
<z64> actually its literally just the hex values of each byte back to back
<FromGitter>
<Blacksmoke16> that would do it
<FromGitter>
<z64> yeah that
<FromGitter>
<jwoertink> yup. I just broke out the PHP one and passed each char to `ord` to match up the bytes
<FromGitter>
<jwoertink> I guess I should have done that the first time lol
<FromGitter>
<jwoertink> thanks for the help all!
<FromGitter>
<z64> 👍
alex`` has quit [Ping timeout: 244 seconds]
<FromGitter>
<jwoertink> Ok, I got the crystal function returning the same as the PHP one! That was pretty tough
<FromGitter>
<jwoertink> In case anyone is curious, the PHP function I had to port was `$encryptedBytes = openssl_encrypt($clearBytes, self::CIPHER, $derived->key, null, $derived->iv);`
<FromGitter>
<tenebrousedge> PHP has improved by leaps and bounds since I first started using it though. Laravel + Psy shell is a very nice dev environment, and the PHP 7 interpreter is blazing fast
<FromGitter>
<Blacksmoke16> he just assigned an instance of it to a const
<FromGitter>
<girng> ```code paste, see link```
<FromGitter>
<j8r> Can be useful with IO stuff, for example
<FromGitter>
<girng> i thought crystal is single threaded, so why is a mutex being used?
<FromGitter>
<j8r> to avoid having simultaneous writes on a given IO
<FromGitter>
<Blacksmoke16> its for fibers
<FromGitter>
<Blacksmoke16> i think
<FromGitter>
<j8r> yes
<FromGitter>
<j8r> fibers are used for concurrency. multi threads are essentially for perf
<FromGitter>
<girng> why use a mutex, when you can spawn a fiber lol
<FromGitter>
<j8r> that's precisely why they are useful
<FromGitter>
<Blacksmoke16> so two fibers dont write to the same file at the same time
<FromGitter>
<girng> oooh
<FromGitter>
<Blacksmoke16> my understanding it would make it so only 1 fiber could write at a time for example
<FromGitter>
<j8r> I think @Blacksmoke16 may have used Mutex in his logger library
<FromGitter>
<j8r> to avoid having at the same time 2 log lines writing to an IO
<FromGitter>
<girng> well how many damn fibers is needed to write to a damn file
<FromGitter>
<Blacksmoke16> i actually didnt but should prob go make it use it :p
<FromGitter>
<Blacksmoke16> kinda forgot about that
<FromGitter>
<girng> it's usually instant isn't it
<FromGitter>
<tenebrousedge> maybe. Maybe you're trying to log a series of web requests, where you're waiting on other IO
<FromGitter>
<tenebrousedge> those could run into each other
<FromGitter>
<Blacksmoke16> like a log file
<FromGitter>
<Blacksmoke16> where each request has its own fiber
<FromGitter>
<tenebrousedge> ^
<FromGitter>
<Blacksmoke16> all writing to the same log file
<FromGitter>
<girng> yeah if they are in its own fiber, it should be fine already? so you need to use multiple fibers and a MUTEX? or what happens if you don't use a mutex, you'll get file writing errors?
<FromGitter>
<Blacksmoke16> tbh im super familiar with it but yea id imagine something would error
<FromGitter>
<girng> i was under the impression the OS just queues the requests internally to write to the file, and performs them in order they are received. this way, you can spawn multiple fibers asynchronously while logging the file.
<FromGitter>
<tenebrousedge> one possibility is that log file entries get inserted out of order due to race conditions
<FromGitter>
<Blacksmoke16> id be interested to see some sample code with that causes two fibers to write to same file
<FromGitter>
<Blacksmoke16> before/after using a mutex
<FromGitter>
<j8r> yes, it would likely be mixed
<FromGitter>
<girng> then when MT gets added.. my mind will become blown even moreso
<FromGitter>
<j8r> mmm, I don't think there will be a problem I we write a string to an IO
<FromGitter>
<j8r> because the IO will be busy and won't be usable by others
<FromGitter>
<j8r> but if we use several `<<` to write to an IO, between those writes another one may write too
<FromGitter>
<girng> that mutex stuff seems too low level for me. too confusing
<FromGitter>
<girng> i'ma just spawn fibers like i usually do. simple, and fast enough / works for my use cases
<FromGitter>
<Blacksmoke16> 😐
<FromGitter>
<Daniel-Worrall> Mutex? Low level?
<FromGitter>
<Daniel-Worrall> Hmmm
<FromGitter>
<j8r> But mutex isn't linked to fibers
<FromGitter>
<j8r> You can use it to "lock" something, to prevent any action
<FromGitter>
<j8r> It's safer than using a Boolean class var
blassin9 has joined #crystal-lang
blassin has quit [Ping timeout: 244 seconds]
_whitelogger has joined #crystal-lang
<FromGitter>
<girng> i mean low level in the sense how c's memory management is low level, but in LUA you don't have to worry about memory management, it's all high level and easier to work with
<FromGitter>
<Daniel-Worrall> I know the context but I disagree with the sentiment