Lisplog

Blogging in Lisp

Search

Feed Aggregator

Rendered on Tue, 15 Oct 2019 13:02:22 GMT  newer latest older 
Next udpate: Tue, 15 Oct 2019 13:30:00 GMT feeds

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @keisisqrl on Tue, 15 Oct 2019 12:32:45 GMT

Huh. I wonder if it trusts 32-bit math (skimming the code, it looks like maybe). I found out trying to implement chacha20 (which I might get back to some day) that 32-bit integers sort of work but act strangely because javascript. I think the Basics module warns about this.

The roll-your-own approach of the icidasset packages seems probably less efficient but it’s guaranteed to work.

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @malaire Markus Laire on Tue, 15 Oct 2019 12:09:49 GMT

Yes, icidasset/elm-sha package actually works unlike billstclair/elm-sha256, which can give incorrect result even for normal strings: https://github.com/billstclair/elm-sha256/issues/7

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @keisisqrl on Tue, 15 Oct 2019 12:04:51 GMT

You could try the elm-sha package which I gather should accept arbitrary byte sequences with a round trip through a hex string (the intermediate representations required might be pretty memory-intensive for a large file, but images or most documents should be okay).

Another option might be to send the file through a port (maybe base64 encode it?) and use the browser subtle crypto API. It’s much less clean though.

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @malaire Markus Laire on Tue, 15 Oct 2019 11:42:21 GMT

I’d consider this to be a bug in Sha256 since it only accepts String as input and not raw Bytes.

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @Nikolis_Galerakis Nikolis Galerakis on Tue, 15 Oct 2019 10:03:38 GMT

Hmm you are right thank you.
Ineed whehn I try that with a txt file works perfectly.
But then do you have any direction on how to aproach this since I specifically want to get the sha256 for jpg files ?

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @Malax Manuel Fuchs on Tue, 15 Oct 2019 09:53:26 GMT

A problem I can see here is, that you’re decoding a bunch of random bytes into an UTF-8 String, but not all byte sequences are valid UTF-8 strings, hence the Nothing. Can you try to select a text file and see if that works?

Edit: I created an Ellie that demonstrates the problem. UTF-8 text files work fine, but some binary files do not. https://ellie-app.com/6W2G972xfwTa1

A reusable rater for Elm

via Elm - Latest posts by @dwayne Dwayne Crooks on Tue, 15 Oct 2019 09:31:13 GMT

Thanks! Yeah, that’s what @Herteby was showing me as well.

Geting the hash sha-256 of a file for upload perpuses

via Elm - Latest posts by @Nikolis_Galerakis Nikolis Galerakis on Tue, 15 Oct 2019 09:19:36 GMT

How can one get the sha-256 hash for a file.

What I am currently trying to do is the following:

import Bytes
import Bytes.Decode  exposing (Decoder)
import Sha256
import File exposing (File)
  1. Select.file [“application/jpeg”] ImmageLoaded)
  2. File.toBytes file to get the bytes of the file
  3. str_dec = Bytes.Decode.string (Bytes.width bytes)
  4. str_hash = Bytes.Decode.decode str_dec bytes

But the result of 4 is alwasys Nothing although the value of Bytes.width is some int number

Anybody has any experience on the topic ? or how would you aproach it ?

How do you approach Html testing?

via Elm - Latest posts by @paulh Paul Hollyer on Tue, 15 Oct 2019 00:53:28 GMT

I was looking for an end to end testing solution, and came across Cypress which I’ve been using successfully for a couple of months now.

I found it to be simple to set up, and comes with some neat features like time travel, automatic reloads when you change your tests, and automatic waiting for elements to load so you don’t need to add waits to your tests.

It will also take snapshots and videos of the test runs.

You can use the test runner locally, and the dashboard service to integrate with Github and CI/CD provider.

(I also just started using Percy for visual testing, which integrates nicely with Cypress, Github, CI/CD)

 newer latest older