Is there a Node.js module that handles AES-CMAC (RFC 4493)?
I've been searching around NPM, Google, and the like, but haven't found one. Somebody within my company built one that wraps Crypto++ as a C++ addon for Node.js, but unfortunately it doesn't build on Windows (depends on make). Just looking for possible alternatives.
This is similar to this other question, but I'm hoping for a Node.js specific implementation instead of a plain JavaScript one. Ideally something that makes use of Node's crypto library or a C/C++ addon for performance.
It seems like it wouldn't be too hard to build one, but I'd like to avoid doing so if there is already one out there.
Since I couldn't find anything, I ended up creating my own module: node-aes-cmac
As I learned more, I discovered that RFC 4493 is specific for 128 bit keys (AES128). But it references the NIST Special Publication 800-38B which gave the additional information I needed to support 192 and 256 bit keys as well.
Related
The Problem
I have JavaScript-like files with extension .gml
I can convert the source to valid JavaScript via magic-string, and can go back the other way using trace-mapping.
I want to leverage Typescript on my .gml files to get strong Intellisense, e.g. by:
Creating a Typescript "program" that acts on the .gml->.js transpiled files and reports issues back; and
Creating a VSCode extension that proxies functionality to the Typescript language server and reverse-source-maps the results back to the editor.
It feels like there should be a relatively straight forward and generalizable approach to this, but my experiments have not worked out. Reference projects are either for much-more-complex scenarios or much simpler ones, and documentation on the matter is very light.
Prior Art
VueJS and Svelte use custom filetypes (.vue and .svelte), which they pre-process into valid Typescript, HTML, and CSS prior to proxying through to those respective language servers.
Their use cases are far more complicated than mine, and their code bases to accomplish this are extensive. I'm hoping to find a much more streamlined approach.
Possible approaches
I've had a little luck following the Svelte approach of creating a Typescript service and hooking up VSCode operations onto it, but this is extremely tedious.
I suspect that there's some possibility of using a Typescript plugin, but as far as I can tell that approach doesn't support using non-js/ts extensions nor source maps.
In any case I know I'll have to do significant work with the to-and-from-sourcemap conversions, but ideally that's the only difficult work I'd need to do.
Questions
Have you seen any examples in the wild of people solving a similar problem, or solved similar problems yourself?
Are there any deep-dive write-ups about this (I've found a few shallow ones)?
Is the plugin approach viable?
What are the possible ways to get non-js/ts extensions recognized by Typescript?
I started learning how to write Cinnamon extensions. Well, I try to ... While I managed to write a first simple desklet, I still didn't find a really good and up to date documentation and introduction.
I have the following questions and would be very glad to get some hints:
What is the best / suggested development workflow?
For now, I do:
copy the changed files from my project directory to .local/share/cinnamon/uuid,
open Melange / Looking Glass,
search there for the extension and reload it via right click
switch to the Log tab and check for errors
Compared to vue.js development with automatic hot-reload of changes in the browser, this seems a bit ... well ... time-consuming.
Where do I find an introduction to the available widgets and widget libraries?
I understood that there is Gtk and St and both have JS / GJS / CJS bindings.
The Gnome Dev Docu doesn't mention St. And I read in another answer here that it seems that shell extensions doesn't use Gtk, but rather St instead (and not in addition?).
I didn't find any documentation for CJS at all, but as far as I understood so far, it seems to be quite similar to GJS. Seems that the way desklets and applets are defined is different?
But now, I still would enjoy to have a (at least brief) introduction which widgets are available. While in Gtk there seems to be a whole set of different list-like widgets, I didn't find any list widget in St. And it seems that I can't use Gtk widgets as children of St widgets ...? This St documentation lacks any overview of available widgets and classes and what they can be used for.
Documentation about events
I found that there is the St.Entry widget that can be used for single-line text input. I found somewhere that I can bind functions to key press key release events like this:
this.input.connect('key-release-event', (widget, event) => {
const input = widget.get_text();
// ...
return true; // event has been handled
});
I didn't managed to get some information for the event.
When printing with JSON.stringify(event) It shows an empty object.
This Gtk documentation looks like there should be fields such as keyval and state, but these are undefined.
This is really kind of frustrating when it takes ages for every very small step to understand ... so, I would really appreciate any hints and suggestions!
Firstly I should note I have no idea what's been happening in CJS since it was split from GJS. Things have been moving pretty fast in GJS, so you may have to ask for help from the Cinnamon community if CJS hasn't been tracking upstream GJS.
The first place you should start is gjs.guide, which is the actively maintained portal for GJS and GNOME Shell extension documentation. There is also an Architecture page which briefly describes the relation of GNOME Shell extensions to the GNOME platform.
Workflow
There is a tiny snippet about how to test an extension by either restarting GNOME Shell or running a nested Shell, but it will need to be expanded at some point:
To restart GNOME Shell in X11, pressing Alt+F2 to open the Run Dialog and enter restart (or just r).
To run new extensions on Wayland you can run a nested gnome-shell using dbus-run-session -- gnome-shell --nested --wayland.
But again, I don't if the above will work with Cinnamon/CJS.
Overview of Widgets
Bindings for GJS are generated from introspection files, which are also used to generate the API documentation. In other words, our "GJS" version of the API documentation will only include material parsed from the C source. In the case of libraries like GLib, Gio, Gtk and so on, you can reference the C documentation for any other material and it should still make sense.
In the case of Clutter, I like to think of it as Gtk if the only widget was GtkWidget, with all of it's machinery. When it comes to St, almost every class is a direct analog of a Gtk widget, such as GtkButton and StButton. If you don't know what a class is for, chances are you can just glance at the Gtk documentation and you'll realize "Oh, StIcon is basically just GtkImage".
Mutter, on the other hand, there is no such high-level tutorials or overviews. It's best just to join Matrix or discourse.gnome.org and ask the community of extension developers and shell developers.
Events
With regard to Clutter.KeyEvent, I had actually forgotten how this situation was a little tricky and non-obvious. Put simply: "events" in this context are sort of polymorphic (I believe they're unions in C) which is why the generated API in GJS is a bit confusing. If you see Clutter.Event.get_key_symbol() and then browse around that page I think it will become clear and you should find all the accessors you need.
Here is the list of key symbol constants and the list of key symbol constans as C definitions in the source might be easier for searching.
I just found https://projects.linuxmint.com/reference/git/cinnamon-tutorials/ that also includes the Cinnamon-specific parts (but haven't looked into the details yet, I'll update :-))
I added some links to the referenced manuals below. For St I did not find an online version yet. But: you can install some dev documentation offline via sudo apt install cinnamon-doc. This adds the Devhelp program in the Programming category of your menu and it has reference manuals for Cinnamon components and for libraries it uses.
Overview
The documentation of Cinnamon is separated into 4 different parts (5
if you count muffin). What you are currently reading is the tutorials,
which includes the general top-level overviews and tutorials you will
need for Cinnamon. This is named “Cinnamon Tutorials”.
The second part is the Javascript reference, which describes the
Javascript part of Cinnamon. This is named the “Cinnamon Javascript
Reference Manual”. This is a technical reference for the individual
functions and objects available in Cinnamon. Note that this
documentation is aimed at both applet/extension developers and
Cinnamon developers themselves. So depending on who you are, some of
the information might be entirely irrelevant.
The third part of the documentation is for the C part of Cinnamon,
which is simply referred to as the “Cinnamon Reference Manual”.
The last part is the documentation for Shell toolkit, or St. This is
the graphical toolkit used to draw widgets on the screen (similar to
Gtk).
The modules covered by the Javascript documentation are those imported
via imports.ui.* and imports.misc.*. The global object is documented
in the C part of Cinnamon, as well as things accessed through
imports.gi.Cinnamon. Things accessed through imports.gi.St are,
unsurprisingly, documented in the St part.
imports.gi.Meta refers to Muffin, while others (eg. imports.gi.Gio)
are third-party (usually GNOME) libraries that are documented
elsewhere.
Accessing the documentation
There are two ways of accessing this documentation, one of which is
what you are currently using. The first method is accessing it online,
which will be available at http://linuxmint.github.io.
The second method is to access it locally. Install the program devhelp
and the cinnamon-doc package (might be named differently in different
distros or included in the cinnamon package itself). Then run the
program devhelp to access all documentations you have installed in
your system (not limited to Cinnamon).
And also worth a look might be the Linux Mint Developer Guide
The CJS repo in GitHub includes also some docs and examples (that are GJS apps in fact, but nevertheless a source of inspiration).
I'm trying to determine which matcher to use for a few different use cases we have. Most importantly we want to replicate the behaviour that the gitignore parser has.
We were considering using globby fast-glob or node-glob. But they all seem to have extended functionality that .gitignore default parsing doesn't provide.
I.e. globby uses fast-glob and fast-glob uses micromatch, which exposes custom functionality. And node-glob also seems extend the default syntax. Hence I've started investigating a little lower down the chain.
I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.
Minimatch
Multimatch
Anymatch
Picomatch
Nanomatch
Micromatch
Observations / Questions:
All of them seem to do file path wildcard matching one way or another (expect anymatch possibly being more generic)
Minimatch is apparently slower than Micromatch, but has the same/similar functionality?
Multimatch seems to be a simple wrapper around minimatch allowing for multiple patterns. Not sure if this is optimised in any way.
Anymatch seems to be very generic. It doesn't seem to know about file path matching?
Picomatch has "full support for standard and extended Bash glob features". I would assume this matches the gitignore processing closely?
Nanomatch seems to extend functionality of Picomatch. Is this more functionality than what the gitignore processor provides?
Micromatch seems to extend functionality of Nanomatch and appears to be a replacement for Minimatch? It claims to be a "drop-in" replacement, however that doesn't seem to be the case looking at the functionality they expose?
Anymatch, Picomatch, Nanomatch and Micromatch are all published under the github organization Micromatch (naming confusion anyone?)
There doesn't seem to be the equivalent of Multimatch for the "Micromatch organization" suite? Or did I just not find it?
The first question to answer is what standard git actually uses to process it's gitignore. And then figure out which package would match that most closely.
This library comparison has been on picomatch for as long as I can remember. It answers all of your questions, and more (full disclosure: I'm the author of picomatch).
I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.
Understandable. Your confusion should be cleared up after reading more about the libraries on their extensive readmes. Each library addresses your questions in great detail.
A quick look on stackoverflow I have not yet found(so hopefully this not duplicate question) similar one(also has long content). I also believe TJ holowaychuck who has created a lot of good node.js (javascript) libraries concluded the same:
The Go stdlib is something I thought was awful when I first heard of
Go, being so used to ultra-modularity in Node, and having experienced
most of Ruby’s stdlib rot. After getting into the language I realized
that most of the stdlib is pretty essential to programs these days,
compression, json, IO, buffered IO, string manipulation and so on. The
bulk of these APIs are well-defined, and powerful. It’s pretty easy to
get by writing entire programs with nearly only consuming the stdlib.
I am looking for a strong user library comparable to for example (java/go) but for node.js(javascript) . Preferable available via package manager(npm) and also very important should be well maintained. If not I think there should be one and programmers should work on it together. We could probably stitch a lot of good libraries together(from npm) and right real solid documentation for this?
For example I just summed up some packages from mostly java:
java.io to provide file io
Provides for system input and output through data streams,
serialization and the file system.
We have fs in node.js but I think might be to minimalistic. I have not yet found strong library for this? Sometimes we pipe() them together with stream libraries like for example through2
javax.swing to have a GUI which looks (almost) some on all platforms
Provides a set of "lightweight" (all-Java language) components that,
to the maximum degree possible, work the same on all platforms.
For this we maybe have electron or nwjs? I also like riot.js for it's simplicity but not yet full of features. We also have bootstrap from twitter just to name a few?
java.util.concurrent
Utility classes commonly useful in concurrent programming.
I know we don't really have threads(concurrency in node.js) but still I think some of these classes could also be in strong user library? Or for example channels like in Go. We have generators/co. There also a lot of good promise libraries like for example bluebird. There are also some channel library on top of generators like for example js-csp.
java.math
Provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal).
But also a lot of other math functions. Again I believe there are already some good ones available but it is hard to find them?
java.util.logging
Provides the classes and interfaces of the JavaTM 2 platform's core logging facilities.
Good logging libraries like for example bunya.
java.util.zip
Provides classes for reading and writing the standard ZIP and GZIP file formats.
java.util.collections
Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).
Like for example the collections from java are really good. I guess you have collectionsjs for that? For time moment.js?
This is more for javascript development but I really like solutions like for example webpack or browserify to not create monolithic beasts. What do you people think. Which libraries do you guys use really a lot for specific use cases(strong user library?). Maybe we should have a poll per category??
P.S: this list is not even complete yet if you ask me but already very long.
Efforts are underway to build such a standard library. One such effort is stdlib, of which I am a contributor. While the project has an emphasis on numerical computing functionality (including statistics, machine learning, and other math), the library also provides more generic utilities commonly found in various libraries and on npm. The project is available for use via npm, has a strong user focus, and prioritizes high-quality (and unified) documentation. Hope this helps!
There are numerous log files that I have to review daily for my job. Several good parsers already exist for these log files but I have yet to find exactly what I want. Well, who could make something more tailored to you than you, right?
The reason I am using JavaScript (other than the fact that I already know it) is because it's portable (no need to install anything) but at the same time cross-platform accessible. Before I invest too much time in this, is this a terrible method of accomplishing my goal?
The input will be entered into a text file, delimited by [x] and the values will be put into an array to make accessing these values faster than pulling the static content.
Any special formatting (numbers, dates, etc) will be dealt with before putting the value in the array to prevent a function from repeating this step every time it is used.
These logs may contain 100k+ lines which will be a lot for the browser to handle. However, each line doesn't contain a ton of information.
I have written some of it already, but with even 10,000 lines it's starting to run slow and I don't know if it's because I wasn't efficient enough or if this just cannot be effectively done. I'm thinking this is because all the data is in one giant table. I'd probably be better off paginating it, but that is less than desirable.
Question 1: Is there anything I failed to mention that I should consider?
Question 2: Would you recommend a better alternative?
Question 3: (A bit off topic, so feel free to ignore). Instead of copy/pasting the input, I would like to 'open' the log file but as far as I know JavaScript cannot do this (for security reasons). Can this be accomplished with a input="file" without actually having a server to upload to? I don't know how SSJS works, but it appears that I underestimated the limitations of JavaScript.
I understand this is a bit vague, but I'm trying to keep you all from having to read a book to answer my question. Let me know if I should include additional details. Thanks!
I think JavaScript is an "ok" choice for this. Using a scripting language to parse log files for personal use is a perfectly sane decision.
However, I would NOT use a browser for this. Web browsers place limitations on how long a bit of javascript can run, or on how many instructions it is allowed to run, or both. If you exceed these limits, you'll get something like this:
Since you'll be working with a large amount of data, I suspect you're going to hit this sooner or later. This can be avoided by clever use of setTimeout, or potentially with web workers, but that will add complexity to your project. This is probably not what you want.
Be aware that JavaScript can run outside of browsers as well. For instance, Windows comes with the Windows Script Host. This will let you run JavaScript from the command prompt, without needing a browser. You won't get the "Script too long" error. As an added bonus, you will have full access to the file system, and the ability to pass command-line arguments to your code.
Good luck and happy coding!
To answer your top question in bold: No, it is not a terrible idea.
If JS is the only language you know, you want to avoid setting up any dependencies, and you want to stay platform-independent... JavaScript seems like a good fit for your particular case.
As a more general rule, I would never use JS as a language to write a desktop app. Especially not for doing a task like log parsing. There are many other languages which are much better suited to this type of problem, like Python, Scala, VB, etc. I mention Python and Scala because of their script-like behaviour and minimal setup requirements. Python also has very similar syntax to JS so it might be easier to pick up then other languages. VB (or any .NET language) would work too if you have a Visual Studio license because of it's easy to use GUI builder if that suits your needs better.
My suggested approach: use an existing framework. There are hundreds, if not thousands of log parsers out there which handle all sorts of use-cases and different formats of logs that you should be able to find something close to what you need. It may just take a little more effort than Google'ing "Log Parsers" to find one that works. If you can't find one that suits your exact needs and you are willing to spend time making your own, you should use that time instead to contribute to one of the existing ones which are open source. Extending an existing code base should always be considered before trying to re-invent the wheel for the 10th gillion time.
Given your invariants "javascript, cross-platform, browser ui, as fast as possible" I would consider this approach:
Use command line scripts (windows: JScript; linux: ?) to parse log files and store 'clean'/relevant data in a SQLite Database (fall back: any decent scripting language can do this, the ready made/specialized tools may be used too)
Use the SQLite Manager addon to do your data mining with SQL
If (2) gets clumsy - use the SQLite Manager code base to 'make something more tailored'
Considering your comment:
For Windows-only work you can use the VS Express edition to write an app in C#, VB.NET, C++/CLI, F#, or even (kind of) Javascript (Silverlight). If you want to stick to 'classic' Javascript and a browser, write a .HTA application (full access to the local machine) and use ADO data(base) access and try to get the (old) DataGrid/Flexgrid controls (they may be installed already; search the registry).