You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.4 KiB

7 years ago
  1. // Generated by CoffeeScript 1.7.1
  2. var CRC, hex;
  3. hex = require('./hex');
  4. module.exports = CRC = (function() {
  5. CRC.prototype.INIT_CRC = 0x00;
  6. CRC.prototype.XOR_MASK = 0x00;
  7. CRC.prototype.WIDTH = 0;
  8. CRC.prototype.pack = function(crc) {
  9. return '';
  10. };
  11. CRC.prototype.each_byte = function(buf, cb) {
  12. var i, _i, _ref, _results;
  13. if (!Buffer.isBuffer(buf)) {
  14. buf = Buffer(buf);
  15. }
  16. _results = [];
  17. for (i = _i = 0, _ref = buf.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
  18. _results.push(cb(buf[i]));
  19. }
  20. return _results;
  21. };
  22. function CRC() {
  23. this.crc = this.INIT_CRC;
  24. }
  25. CRC.prototype.digest_length = function() {
  26. return Math.ceil(this.WIDTH / 8.0);
  27. };
  28. CRC.prototype.update = function(data) {};
  29. CRC.prototype.reset = function() {
  30. return this.crc = this.INIT_CRC;
  31. };
  32. CRC.prototype.checksum = function(signed) {
  33. var sum;
  34. if (signed == null) {
  35. signed = true;
  36. }
  37. sum = this.crc ^ this.XOR_MASK;
  38. if (signed) {
  39. sum = sum >>> 0;
  40. }
  41. return sum;
  42. };
  43. CRC.prototype.finish = function() {
  44. return this.pack(this.checksum());
  45. };
  46. CRC.prototype.hexdigest = function(value) {
  47. var result;
  48. if (value != null) {
  49. this.update(value);
  50. }
  51. result = this.finish();
  52. this.reset();
  53. return result;
  54. };
  55. return CRC;
  56. })();