Changeset 299
- Timestamp:
- 10/13/06 17:59:32 (2 years ago)
- Location:
- trunk/thune
- Files:
-
- 1 added
- 4 modified
-
doc/UserManual (modified) (1 diff)
-
files.c (modified) (1 diff)
-
support/sha1.c (added)
-
urlan.c (modified) (1 diff)
-
urlan_atoms.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/doc/UserManual
r294 r299 459 459 to-hex (int -- int) Flag integer to display in hexadecimal. 460 460 to-dec (int -- int) Flag integer to display in decimal. 461 checksum (bin type -- digest) Compute 'crc16 or 'sha1 checksum. 461 462 =========== ====================== ====================== 462 463 -
trunk/thune/files.c
r279 r299 744 744 745 745 746 // (binary -- int) 746 #define SHA1HANDSOFF 1 747 #include <support/sha1.c> 748 749 750 // (binary type -- int) 747 751 UR_CALL( uc_checksum ) 748 752 { 753 UCell* res; 749 754 char* cpA; 750 755 char* cpB; 751 756 752 UR_CALL_UNUSED_TH 753 754 if( ur_binarySlice( tos, &cpA, &cpB ) ) 755 { 756 ur_initType(tos, UT_INT); 757 ur_int(tos) = checksum_crc16( (uint8_t*) cpA, cpB - cpA ); 757 if( ! ur_isAWord( tos ) ) 758 goto typeErr; 759 760 UR_S_DROP; 761 res = UR_TOS; 762 763 if( ur_binarySlice( res, &cpA, &cpB ) ) 764 { 765 switch( ur_atom(tos) ) 766 { 767 case UR_ATOM_CRC16: 768 ur_initType(res, UT_INT); 769 ur_int(res) = checksum_crc16( (uint8_t*) cpA, cpB - cpA ); 770 return; 771 772 case UR_ATOM_SHA1: 773 { 774 SHA1_CTX context; 775 UIndex binN; 776 UBinary* bin; 777 778 binN = ur_makeBinary( 20 ); 779 bin = ur_binPtr( binN ); 780 bin->used = 20; 781 782 SHA1Init( &context ); 783 SHA1Update( &context, (uint8_t*) cpA, cpB - cpA ); 784 SHA1Final( bin->ptr.b, &context ); 785 786 ur_initType(res, UT_BINARY); 787 ur_setSeries(res, binN, 0); 788 } 789 return; 790 } 791 goto typeErr; 758 792 } 759 793 else 760 794 { 761 ur_setNone(tos); 762 } 795 ur_throwErr( UR_ERR_DATATYPE, "checksum expected binary!" ); 796 return; 797 } 798 799 typeErr: 800 801 ur_throwErr( UR_ERR_DATATYPE, "checksum expected type 'crc16 or 'sha1" ); 763 802 } 764 803 -
trunk/thune/urlan.c
r276 r299 269 269 FIXED_ATOM( "append", 6, UR_ATOM_APPEND ) 270 270 271 // Checksum types 272 FIXED_ATOM( "crc16", 5, UR_ATOM_CRC16 ) 273 FIXED_ATOM( "sha1", 4, UR_ATOM_SHA1 ) 274 271 275 FIXED_ATOM( "reader-macros", 13, UR_ATOM_READER_MACROS ) 272 276 -
trunk/thune/urlan_atoms.h
r276 r299 42 42 #define UR_ATOM_WRITE 105 43 43 #define UR_ATOM_APPEND 106 44 #define UR_ATOM_READER_MACROS 107 44 #define UR_ATOM_CRC16 107 45 #define UR_ATOM_SHA1 108 46 #define UR_ATOM_READER_MACROS 109
