EntropySink

Technical & Scientific => Programming => Topic started by: Rob on February 26, 2013, 08:13:04 AM

Title: Javascript Help: wtf?
Post by: Rob on February 26, 2013, 08:13:04 AM
Can one of you kind Java / Javascript experts interpret what this segment of code does please?

(Not what the functionality is, but literally what functions are being called, with what parameters etc.)

Code: [Select]
function SecureContext(strText, strSignature, bEscape) {
this.strSIGNATURE = strSignature || '';
this.bESCApE = bEscape || false;
this.strText = strText;
this.escape = SecureContext_escape;
this.unescape = SecureContext_unescape;
this.transliterate = SecureContext_transliterate;
this.encypher = SecureContext_encypher;
this.decypher = SecureContext_decypher;
this.sign = SecureContext_sign;
this.unsign = SecureContext_unsign;
this.secure = SecureContext_secure;
this.unsecure = SecureContext_unsecure;
}


If it helps, it's from here (http://www.inet.hr/~tsereg/en/jse/security.js) ( http://www.inet.hr/~tsereg/en/jse/index.html )

Ta!

edit>> It's these kind of lines I don't understand..

this.secure = SecureContext_secure;

Is that calling SecureContext_secure ? If so, where are the parameters? Surely it should be passing strPassword?

Code: [Select]
function SecureContext_secure( strPasswd )
{
    var passwd = new Password( strPasswd );
    var anPerm   = passwd.getPermutation()
this.sign( anPerm.length );
this.transliterate( true );
this.encypher( anPerm );
}
Title: Re: Javascript Help: wtf?
Post by: Mike on February 26, 2013, 10:00:28 AM
No, it's not calling it.  It is setting a reference to it.  So that
Code: [Select]
foo = new SecureContent(stuff)
foo.secure(more stuff)
invokes SecureContext_secure

Think function pointer.
Title: Re: Javascript Help: wtf?
Post by: Rob on February 26, 2013, 10:17:10 AM
OK, thank you. That makes perfect sense.