Spherical forums

Sphere Development => Engine Development => Topic started by: Rahkiin on March 20, 2014, 08:05:39 pm

Title: Advances in the Sphere JavaScript Library
Post by: Rahkiin on March 20, 2014, 08:05:39 pm
Hi All!

I have a couple of matters regarding the JavaScript library provided for Sphere:

Today I was coding on my engine, and I came across the Logging API in the function docs on the wiki.
I started to wonder, does anyone use this logging api? Especially more than just the 'print a line to a file': the grouping?

I am adding SHA1 and SHA256 hashing functions for files and raw files. It might be a good addition as MD5 is completely broken. I keep MD5 for legacy reasons.


// Rahkiin
Title: Re: Advances in the Sphere JavaScript Library
Post by: Radnen on March 20, 2014, 08:30:57 pm
It's used extensively in a lot of older projects. Tung's persist.js for example is one of them. It is underused however, and most just generally print a line to file. I think it's a neat feature worth keeping. If you want to 'upgrade' that feature feel free to, and if you want to strip it you can too, since it is mainly used for debugging afterall. Make sure to gracefully fail if you do strip it out in case a game uses it, at least it'll just do nothing instead of fail.
Title: Re: Advances in the Sphere JavaScript Library
Post by: Rahkiin on March 20, 2014, 08:32:20 pm
Alright. I'll look into making a nicer debug/log-api.

I edited my post to add about hashing.
Title: Re: Advances in the Sphere JavaScript Library
Post by: Radnen on March 20, 2014, 11:59:55 pm
While it is true MD5 is broken for security reasons, it still has a use. For example, you may want to compare two files or other pieces of data, it's not so bad and cheaper and easier than SHA. While on the topic of broken encryption algorithms, SHA-1 is broken too so SHA-256 is really your best bet. I too added SHA-1/256 to my Sphere engine. So +1 on that feature.
Title: Re: Advances in the Sphere JavaScript Library
Post by: Rahkiin on March 21, 2014, 01:11:07 am
What is the API you are using? I have my FileSystem.md5()/sha1/sha256, FileSystem.File.prototype.md5/sha1/sha256 and same for RawFile. Do you have some SHA1HashForFile() function?
Title: Re: Advances in the Sphere JavaScript Library
Post by: Radnen on March 21, 2014, 02:18:32 am
My engine re-implements the old Sphere API for backwards game compliance. My shim will be different and do the opposite of the kind of shim you'd make.

Example:
Code: (javascript) [Select]

HashFromFile(filename, sha); // sha = true, hashes in sha-1, sha=false or undefined, hashes in MD5


This way the old functionality still works if you don't add SHA as a parameter, and if you do you can instantly upgrade your project from the old MD5 hash to the newer SHA hashes. Now, I use SHA-1 for now, but soon I'll change this API to take a constant so you can go between MD5, various types of SHA and other types of hash functions.
Title: Re: Advances in the Sphere JavaScript Library
Post by: Rahkiin on March 21, 2014, 01:20:56 pm
Alright. We should be making some documentation for each engine, so we can create shims for it. I create a shim for 1.6, and 1.5, and I can add any shim I want of course. I wondered about your API so I can incorporate that in the shim.