519 or an externalBytes object (with known size)" |
519 or an externalBytes object (with known size)" |
520 |
520 |
521 %{ |
521 %{ |
522 INT len, offs; |
522 INT len, offs; |
523 INT objSize; |
523 INT objSize; |
524 int nInstVars, nInstBytes; |
524 int nInstBytes; |
525 char *extPtr; |
525 char *extPtr; |
526 |
526 |
527 if (__isByteArray(__INST(hashContext)) |
527 if (__isByteArray(__INST(hashContext)) |
528 && __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX) |
528 && __byteArraySize(__INST(hashContext)) == sizeof(SHA1_CTX) |
529 && __bothSmallInteger(count, start) |
529 && __bothSmallInteger(count, start) |
530 ) { |
530 ) { |
531 SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element; |
531 SHA1_CTX *ctx = (SHA1_CTX *)__ByteArrayInstPtr(__INST(hashContext))->ba_element; |
532 |
532 |
533 len = __intVal(count); |
533 len = __intVal(count); |
534 offs = __intVal(start) - 1; |
534 offs = __intVal(start) - 1; |
535 |
535 |
536 if (__isExternalBytesLike(anObject)) { |
536 if (__isExternalBytesLike(anObject)) { |
537 OBJ sz; |
537 OBJ sz; |
538 |
538 |
539 nInstBytes = 0; |
539 nInstBytes = 0; |
540 extPtr = (char *)__externalBytesAddress(anObject); |
540 extPtr = (char *)__externalBytesAddress(anObject); |
541 if (extPtr == NULL) goto bad; |
541 if (extPtr == NULL) goto bad; |
542 sz = __externalBytesSize(anObject); |
542 sz = __externalBytesSize(anObject); |
543 if (__isSmallInteger(sz)) { |
543 if (__isSmallInteger(sz)) { |
544 objSize = __intVal(sz); |
544 objSize = __intVal(sz); |
545 } else { |
545 } else { |
546 objSize = 0; /* unknown */ |
546 objSize = 0; /* unknown */ |
547 } |
547 } |
548 } else { |
548 } else { |
549 OBJ oClass; |
549 OBJ oClass = __Class(anObject); |
550 |
550 int nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
551 oClass = __Class(anObject); |
551 |
552 switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
552 nInstBytes = OHDR_SIZE + __OBJS2BYTES__(nInstVars); |
553 case BYTEARRAY: |
553 switch (__intVal(__ClassInstPtr(oClass)->c_flags) & ARRAYMASK) { |
554 case WORDARRAY: |
554 case BYTEARRAY: |
555 case LONGARRAY: |
555 case WORDARRAY: |
556 case SWORDARRAY: |
556 case LONGARRAY: |
557 case SLONGARRAY: |
557 case SWORDARRAY: |
558 case FLOATARRAY: |
558 case SLONGARRAY: |
559 case DOUBLEARRAY: |
559 case FLOATARRAY: |
560 break; |
560 break; |
561 default: |
561 case DOUBLEARRAY: |
562 goto bad; |
562 #ifdef __NEED_DOUBLE_ALIGN |
563 } |
563 nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
564 nInstVars = __intVal(__ClassInstPtr(oClass)->c_ninstvars); |
564 #endif |
565 nInstBytes = __OBJS2BYTES__(nInstVars); |
565 break; |
566 // nInstBytes is the number of bytes occupied by pointer instance variables |
566 case LONGLONGARRAY: |
567 // subtract from size and add to byte-pointer |
567 case SLONGLONGARRAY: |
568 objSize = __Size(anObject) - OHDR_SIZE - nInstBytes; |
568 #ifdef __NEED_LONGLONG_ALIGN |
569 extPtr = (char *)__byteArrayVal(anObject)+nInstBytes; |
569 nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
570 } |
570 #endif |
571 if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) { |
571 break; |
572 SHA1Update(ctx, extPtr+offs, (unsigned int)len); |
572 default: |
573 RETURN (count); |
573 goto bad; |
574 } |
574 } |
|
575 // nInstBytes is the number of bytes occupied by pointer instance variables |
|
576 // subtract from size and add to byte-pointer |
|
577 objSize = __Size(anObject) - nInstBytes; |
|
578 extPtr = (char *)anObject + nInstBytes; |
|
579 } |
|
580 if ((offs >= 0) && (len >= 0) && (objSize >= (len + offs))) { |
|
581 SHA1Update(ctx, extPtr+offs, (unsigned int)len); |
|
582 RETURN (count); |
|
583 } |
575 } |
584 } |
576 bad: ; |
585 bad: ; |
577 %}. |
586 %}. |
578 |
587 |
579 ^ self primitiveFailed |
588 ^ self primitiveFailed |
580 ! ! |
589 ! ! |
581 |
590 |
582 !SHA1Stream class methodsFor:'documentation'! |
591 !SHA1Stream class methodsFor:'documentation'! |
583 |
592 |
584 version |
593 version |
585 ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.40 2014-01-25 00:31:18 cg Exp $' |
594 ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.45 2014-02-12 15:25:24 stefan Exp $' |
586 ! |
595 ! |
587 |
596 |
588 version_CVS |
597 version_CVS |
589 ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.40 2014-01-25 00:31:18 cg Exp $' |
598 ^ '$Header: /cvs/stx/stx/libbasic/SHA1Stream.st,v 1.45 2014-02-12 15:25:24 stefan Exp $' |
590 ! ! |
599 ! ! |
591 |
600 |
592 |
601 |
593 SHA1Stream initialize! |
602 SHA1Stream initialize! |