Node-RSA/node-asn1 error : Expected 0x30: got 0x37 - node.js

I'm using NodeRSA to verify the signature of a given data thanks to a public key.
When I'm initiating NodeRSA, an error is thrown, which comes from a module used by NodeRSA : node-asn1.
The error is Expected 0x30: got 0x37.
I dove into the code and identified the exact line where the error occurred, but as I'm a newbie in crypto, I couldn't really find any solution.
var reader = new ber.Reader(buffer);
reader.readSequence();
var header = new ber.Reader(reader.readString(0x30, true));
I know some errors are expecting 0x2, which is the start of text. But I can't understand why we are expecting a 0 (0x30) and we've got a 7 (0x37) instead.
Would you have any solutions, or even ideas that I could dive into ?

Related

Suddenly getting Typescript error TS2322, type not assignable errors during build process

I have APIs written in lambda, exposed via API Gateway using Koa. I use AWS Codebuild for my deployment.
Recently Codebuild has started throwing the following error when the build process starts:
src/components/chart-color-settings/chart-color-settings.ts(11,13): error TS2322: Type 'string | string[] | undefined' is not assignable to type 'string | undefined'.
Type 'string[]' is not assignable to type 'string'.
It throws this error in some of the files where I am reading query param and passing it to a function.
For example
import { Context } from "koa";
static async getChartColorSetting(ctx: Context) {
const handlerFactory = ChartColorSettingsHandlerFactory.getInstance(dbService);
let chartType: string | undefined = ctx.request.query.chartType; //this is where it says the problem is
let result = await handlerFactory.getChartColorSetting(chartType)
//rest of the code
}
Earlier it never complained about this problem. Suddenly it has started failing the builds because it "thinks" it will receive either string[] in the ctx.request.query or the function accepts some other type of param
Nothing has changed in that code, also it is showing similar build failure errors in other places where I am reading from ctx.request.query and giving me "not assignable" errors
Codebuild error below:
Whereas the actual code for the error it is talking about looks like this:
As you can see from the code screenshot from above that the method tranlateHolidayInShifts is expecting the right type of params as read via the ctx.request.query.
I have no idea to what has caused this all of a sudden.
Any ideas or suggestions to fix this once and for all so the builds don't keep failing.
Thank you.
Error said type string[] is not assignable to type 'string', So i think u can try declare ur variable from string to array of string:
let chartType: string[] | undefined = ctx.request.query.chartType;
The reason this error may have suddenly appeared is because you're not committing either the "package-lock.json" or "yarn.lock" files.

How can i use ‚momentjs‘ in a ‚binary-parser‘ formatter?

Can anybody help me please. How can i use moment in a formatter?
i think this is not a problem from node or binary parser. it is my understanding i think.
const Parser = require("binary-parser").Parser;
const moment = require('moment');
let time = function(timestamp) {
return moment(timestamp, 'YYMMDDHHmmssSS').format('YYYY-MM-DD HH:mm:ss.SS');
};
let Telegram = new Parser()
.string('timestamp', {encoding: 'hex', length: 7, formatter: time});
The Exception is:
evalmachine.:9
return moment(timestamp, 'YYMMDDHHmmssSS').format('YYYY-MM-DD HH:mm:ss.SS');
^
ReferenceError: moment is not defined
at Parser. (evalmachine.:9:2)
...
I think the Problem is that Parser don't know moment. But how can i realize that?
i have tried to import moment directly in the binary-parser module. But it doesn't working.
If i run moment outside of Parser then it is working.
Maybe anybody can help me.
The formatter function runs without the momentjs context. I am guessing because of the way it consumes the formatter property. In the code found here, the code is:
if (this.code.formatter) {
... (ctx, varName, this.options.formatter)
Because of the funny way the this keyword works, it's bound to the object (options) and because that declaration does not contain momentjs, it says that it is not defined.
You can get a better understanding of this by looking at line 735:
ctx.pushCode("{0} = ({1}).call(this, {0});", varName, formatter);
It's bound to the current object.
P.S.: I copied the code and pasted it on Node.js and it's working perfectly. ^That is a possible explanation.

List of Cassandra error codes

While using the datastax node.js driver I'm getting an exception code as documented under http://docs.datastax.com/en/developer/nodejs-driver-dse/1.4/api/module.errors/class.ResponseError/.
However I cannot find any documentation about all available exception codes. Anybody an idea where to find?
I'm not sure that the code values are specifically documented anywhere but you could always look at the ExceptionCode source for the version of Cassandra you are working with.
On trunk this lists the errors as:
SERVER_ERROR (0x0000),
PROTOCOL_ERROR (0x000A),
BAD_CREDENTIALS (0x0100),
// 1xx: problem during request execution
UNAVAILABLE (0x1000),
OVERLOADED (0x1001),
IS_BOOTSTRAPPING (0x1002),
TRUNCATE_ERROR (0x1003),
WRITE_TIMEOUT (0x1100),
READ_TIMEOUT (0x1200),
READ_FAILURE (0x1300),
FUNCTION_FAILURE (0x1400),
WRITE_FAILURE (0x1500),
CDC_WRITE_FAILURE (0x1600),
// 2xx: problem validating the request
SYNTAX_ERROR (0x2000),
UNAUTHORIZED (0x2100),
INVALID (0x2200),
CONFIG_ERROR (0x2300),
ALREADY_EXISTS (0x2400),
UNPREPARED (0x2500);
The response error codes are not properly documented in the driver, I've created a ticket for it: https://datastax-oss.atlassian.net/browse/NODEJS-418
In the meantime, you should be getting code completion on your IDE (VS Code / WebStorm) and/or look at the code:
const responseErrorCodes = {
serverError: 0x0000,
protocolError: 0x000A,
badCredentials: 0x0100,
unavailableException: 0x1000,
overloaded: 0x1001,
isBootstrapping: 0x1002,
truncateError: 0x1003,
writeTimeout: 0x1100,
readTimeout: 0x1200,
readFailure: 0x1300,
functionFailure: 0x1400,
writeFailure: 0x1500,
syntaxError: 0x2000,
unauthorized: 0x2100,
invalid: 0x2200,
configError: 0x2300,
alreadyExists: 0x2400,
unprepared: 0x2500
};
To check against a certain error code, you should use something like:
if (err.code === cassandra.types.responseErrorCodes.syntaxError) {
// ...
}

Error "Unable to get property 'normalize' of undefined or null reference" in require.js with text.js

I'm making my first attempt at using the text.js plugin (v2.0.12) for require.js (v2.1.15). I've had require working well up to this point, however, when I attempt to resolve a text dependency, I get two errors. The first error is Unable to get property 'normalize' of undefined or null reference [require.js, Line: 955] then, after the allotted time, I'll get a timeout error for the html file I'm attempting to load. The focus of this cry for help is the former error.
One curious observation I've noticed is that if I resolve the text module without declaring a file, there is no error. However, when I add the file path e.g. text!path/file, the error is triggered.
Additionally, I noticed that the load timeout error references the text module with _unnormalized2 appended. Not sure if that's to be expected but I thought is odd. Any help would be greatly appreciated!
Here's the block of code which errors:
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) { // error occurs here (line 955)
name = plugin.normalize(name, function (name) {
return normalize(name, parentName, true);
}) || '';
}
// ...
}
Ok, it turns out to have been a self-sabotage! I was creating a shortcut definition for the text module for which I left out the factory method. So, instead of
define('text', ['Scripts/text'], function(text) { return text; });
I had:
define('text', ['Scripts/text']);
Nothing to do with text.js whatsoever.

Strange Error in using consolelog in nodejs

Using node.js 0.10.24.
I got an error telling me that "Object has no method log" in 6th line in following code.
But when 3rd line enabled, no problem. Anyone know why?
var EE=require("events").EventEmitter;
var on=EE.prototype.on;
//var c=console;
EE.prototype.on=function(event,handler){
console.log("added "+event);
on.call(this,event,handler);
};
var server=require('http').createServer();

Resources