sha256sum.myr 902 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. use std
  2. use bio
  3. use crypto
  4. use "dispatch"
  5. const sha256sum = {params
  6. var f, ofile
  7. var st, hash
  8. var buf : byte[1024]
  9. var b
  10. ofile=params[0]
  11. match bio.open(ofile, bio.Rd)
  12. | `std.Ok bio: f = bio
  13. | `std.Err e: std.fatal("Unable to open data file: {}\n", e)
  14. ;;
  15. crypto.sha256init(&st)
  16. while true
  17. b= r(f, buf[:])
  18. match b
  19. | "": break;
  20. | _:
  21. //std.put("{}\n",b)
  22. crypto.sha256add(&st,b)
  23. ;;
  24. ;;
  25. hash = crypto.sha256fin(&st)
  26. // komple raw data yazıyoruz
  27. std.put("{r}",hash[:])
  28. /* hex integer yazmak için
  29. for h : hash
  30. std.put("{x}", h)
  31. ;;
  32. */
  33. std.put("\n")
  34. }
  35. const r = {f, buf
  36. match bio.read(f, buf)
  37. | `std.Ok b:
  38. -> b
  39. | `std.Err `bio.Eof:
  40. std.put("eof\n")
  41. -> ""
  42. | `std.Err e:
  43. std.put("err\n")
  44. -> ""
  45. ;;
  46. }
  47. const __init__ = {
  48. dispatch.register("sha256sum", sha256sum)
  49. }