@@ -33,6 +33,15 @@ crypto.DEFAULT_ENCODING = 'buffer';
3333// bump, we register a lot of exit listeners
3434process . setMaxListeners ( 256 ) ;
3535
36+ const errMessages = {
37+ offsetNotNumber : / ^ T y p e E r r o r : o f f s e t m u s t b e a n u m b e r $ / ,
38+ offsetOutOfRange : / ^ R a n g e E r r o r : o f f s e t o u t o f r a n g e $ / ,
39+ offsetNotUInt32 : / ^ T y p e E r r o r : o f f s e t m u s t b e a u i n t 3 2 $ / ,
40+ sizeNotNumber : / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r $ / ,
41+ sizeNotUInt32 : / ^ T y p e E r r o r : s i z e m u s t b e a u i n t 3 2 $ / ,
42+ bufferTooSmall : / ^ R a n g e E r r o r : b u f f e r t o o s m a l l $ / ,
43+ } ;
44+
3645const expectedErrorRegexp = / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r > = 0 $ / ;
3746[ crypto . randomBytes , crypto . pseudoRandomBytes ] . forEach ( function ( f ) {
3847 [ - 1 , undefined , null , false , true , { } , [ ] ] . forEach ( function ( value ) {
@@ -41,10 +50,10 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
4150 expectedErrorRegexp ) ;
4251 } ) ;
4352
44- [ 0 , 1 , 2 , 4 , 16 , 256 , 1024 ] . forEach ( function ( len ) {
53+ [ 0 , 1 , 2 , 4 , 16 , 256 , 1024 , 101.2 ] . forEach ( function ( len ) {
4554 f ( len , common . mustCall ( function ( ex , buf ) {
4655 assert . strictEqual ( ex , null ) ;
47- assert . strictEqual ( buf . length , len ) ;
56+ assert . strictEqual ( buf . length , Math . floor ( len ) ) ;
4857 assert . ok ( Buffer . isBuffer ( buf ) ) ;
4958 } ) ) ;
5059 } ) ;
@@ -139,14 +148,6 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
139148 Buffer . alloc ( 10 ) ,
140149 new Uint8Array ( new Array ( 10 ) . fill ( 0 ) )
141150 ] ;
142- const errMessages = {
143- offsetNotNumber : / ^ T y p e E r r o r : o f f s e t m u s t b e a n u m b e r $ / ,
144- offsetOutOfRange : / ^ R a n g e E r r o r : o f f s e t o u t o f r a n g e $ / ,
145- offsetNotUInt32 : / ^ T y p e E r r o r : o f f s e t m u s t b e a u i n t 3 2 $ / ,
146- sizeNotNumber : / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r $ / ,
147- sizeNotUInt32 : / ^ T y p e E r r o r : s i z e m u s t b e a u i n t 3 2 $ / ,
148- bufferTooSmall : / ^ R a n g e E r r o r : b u f f e r t o o s m a l l $ / ,
149- } ;
150151
151152 const max = require ( 'buffer' ) . kMaxLength + 1 ;
152153
@@ -264,4 +265,4 @@ const expectedErrorRegexp = /^TypeError: size must be a number >= 0$/;
264265// length exceeds max acceptable value"
265266assert . throws ( function ( ) {
266267 crypto . randomBytes ( ( - 1 >>> 0 ) + 1 ) ;
267- } , / ^ T y p e E r r o r : s i z e m u s t b e a n u m b e r > = 0 $ / ) ;
268+ } , errMessages . sizeNotUInt32 ) ;
0 commit comments