|
| 1 | +// Copyright Joyent, Inc. and other Node contributors. |
| 2 | +// |
| 3 | +// Permission is hereby granted, free of charge, to any person obtaining a |
| 4 | +// copy of this software and associated documentation files (the |
| 5 | +// "Software"), to deal in the Software without restriction, including |
| 6 | +// without limitation the rights to use, copy, modify, merge, publish, |
| 7 | +// distribute, sublicense, and/or sell copies of the Software, and to permit |
| 8 | +// persons to whom the Software is furnished to do so, subject to the |
| 9 | +// following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included |
| 12 | +// in all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 | +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
| 17 | +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 18 | +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 19 | +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
| 20 | +// USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +// This is the same as test/simple/test-crypto, but from before the shift |
| 23 | +// to use buffers by default. |
| 24 | + |
| 25 | + |
| 26 | +var common = require('../common'); |
| 27 | +var assert = require('assert'); |
| 28 | + |
| 29 | +try { |
| 30 | + var crypto = require('crypto'); |
| 31 | +} catch (e) { |
| 32 | + console.log('Not compiled with OPENSSL support.'); |
| 33 | + process.exit(); |
| 34 | +} |
| 35 | + |
| 36 | +var EXTERN_APEX = 0xFBEE9; |
| 37 | + |
| 38 | +// manually controlled string for checking binary output |
| 39 | +var ucs2_control = 'a\u0000'; |
| 40 | + |
| 41 | +// grow the strings to proper length |
| 42 | +while (ucs2_control.length <= EXTERN_APEX) { |
| 43 | + ucs2_control += ucs2_control; |
| 44 | +} |
| 45 | + |
| 46 | + |
| 47 | +// check resultant buffer and output string |
| 48 | +var b = new Buffer(ucs2_control + ucs2_control, 'ucs2'); |
| 49 | + |
| 50 | +// |
| 51 | +// Test updating from birant data |
| 52 | +// |
| 53 | +(function() { |
| 54 | + var datum1 = b.slice(700000); |
| 55 | + var hash1_converted = crypto.createHash('sha1') |
| 56 | + .update(datum1.toString('base64'), 'base64') |
| 57 | + .digest('hex'); |
| 58 | + var hash1_direct = crypto.createHash('sha1').update(datum1).digest('hex'); |
| 59 | + assert.equal(hash1_direct, hash1_converted, 'should hash the same.'); |
| 60 | + |
| 61 | + var datum2 = b; |
| 62 | + var hash2_converted = crypto.createHash('sha1') |
| 63 | + .update(datum2.toString('base64'), 'base64') |
| 64 | + .digest('hex'); |
| 65 | + var hash2_direct = crypto.createHash('sha1').update(datum2).digest('hex'); |
| 66 | + assert.equal(hash2_direct, hash2_converted, 'should hash the same.'); |
| 67 | +})(); |
0 commit comments