UNPKG

bip-pod-flow

Version:
55 lines (47 loc) 1.64 kB
/** * * The Bipio Flow Pod. nonce action definition * --------------------------------------------------------------- * * Copyright (c) 2017 InterDigital, Inc. All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function Nonce(podConfig) { } Nonce.prototype = {}; function randStr (bits) { var chars, rand, i, ret; chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'; ret = ''; // in v8, Math.random() yields 32 pseudo-random bits (in spidermonkey it gives 53) while (bits > 0) { // 32-bit integer rand = Math.floor(Math.random() * 0x100000000); // base 64 means 6 bits per character, so we use the top 30 bits from rand to give 30/6=5 characters. for (i = 26; i > 0 && bits > 0; i -= 6, bits -= 6) { ret += chars[0x3F & rand >>> i]; } } return ret; } /** * Invokes (runs) the action. */ Nonce.prototype.invoke = function(imports, channel, sysImports, contentParts, next) { next(false, { 'nonce' : randStr(64) }); } // ----------------------------------------------------------------------------- module.exports = Nonce;