Commits

watermelon committed 8b5061a

input validation is only done in uicontroller, nothing invalid shall pass uicontroller;
therefore removed redundant parameter checking

  • Participants
  • Parent commits b6f7a32

Comments (0)

Files changed (5)

File src/main/client/crypto/BookmarkCrypto.js

 	 * ************************/
 	
 	//the key for the symmetrical de/encryption.
-	if(typeof _symmKey == 'undefined')
-		throw "_symmKey is undefined.";
-	else if(Object.prototype.toString.call(_symmKey) == "[object String]")
-			var symmKey = _symmKey;
-	else
-		throw "illegal argument _symmKey.";
-	
+	var symmKey = _symmKey;
 	
 	
 	/* ************************

File src/main/client/crypto/UserCrypto.js

 	 * ************************/
 	
 	//the private key
-	if(typeof _rsa_private_key_pem_encrypted == 'undefined')
-		throw "_rsa_private_key_pem_encrypted is undefined.";
-	else if(Object.prototype.toString.call(_rsa_private_key_pem_encrypted) == "[object String]")
-		var rsa_private_key_pem_encrypted = _rsa_private_key_pem_encrypted;
-	else
-		throw "illegal argument _rsa_private_key_pem_encrypted.";
-	
-	
+	var rsa_private_key_pem_encrypted = _rsa_private_key_pem_encrypted;
 	
 	//the public key
-	if(typeof _rsa_public_key_pem == 'undefined')
-		throw "_rsa_public_key_pem is undefined.";
-	else if(Object.prototype.toString.call(_rsa_public_key_pem) == "[object String]")
-		this.rsa_public_key_pem = _rsa_public_key_pem;
-	else
-		throw "illegal argument _rsa_private_key_pem_encrypted.";
+	this.rsa_public_key_pem = _rsa_public_key_pem;
 	
 	
 	//parse pem
-	var rsa_params = {};
-	rsa_params = bookmaak.crypto.CryptoUtils.parseCert(rsa_private_key_pem_encrypted);
+	var rsa_params = bookmaak.crypto.CryptoUtils.parseCert(rsa_private_key_pem_encrypted);
 	
-	if(!(rsa_params.iv
-	&& rsa_params.salt
-	&& rsa_params.mode == 'CBC'
-	&& rsa_params.aes
-	&& rsa_params.bits
-	&& rsa_params.b64)) {
-		
-		throw "Invalid rsa private key certificate.";
-	}
-	else {
-		
-		//decrypt and set
-		var rsa_private_key_asn = bookmaak.crypto.CryptoUtils.decryptPrivateKey(rsa_params);
-		
-		//asn.toHexTree() returns the parameters used for RSA intialization
-		//@returns node: as javascript object tree with hex strings as values
-		var asnTree = rsa_private_key_asn.toHexTree();
-		
-		//initializing RSA module
-		var rsa = new pidCrypt.RSA();
-		
-		//set RSA parameters from ASN.1 structure
-		rsa.setPrivateKeyFromASN(asnTree);
-	}
+	//decrypt and set
+	var rsa_private_key_asn = bookmaak.crypto.CryptoUtils.decryptPrivateKey(rsa_params);
+	
+	//asn.toHexTree() returns the parameters used for RSA intialization
+	//@returns node: as javascript object tree with hex strings as values
+	var asnTree = rsa_private_key_asn.toHexTree();
+	
+	//initializing RSA module
+	var rsa = new pidCrypt.RSA();
+	
+	//set RSA parameters from ASN.1 structure
+	rsa.setPrivateKeyFromASN(asnTree);
 	
 	
 	/* ************************
 	 **/
 	this.encryptUserFile = function(plain_file) {
 		
-		var _type = plain_file.type;
-		if(typeof _type == 'undefined'
-			|| _type != bookmaak.controller.FILE_TYPE.USER)
+		var type = plain_file.type;
+		
+		if(type != bookmaak.controller.FILE_TYPE.USER)
 			throw "plain_file is undefined or of wrong type";
-		else
-			var type = plain_file.type;
 		
 		var data_decrypted = plain_file.data;
 		

File src/main/client/dao/BookmarkDao.js

 	 * ************************/
 	
 	//the file name of the bookmark store
-	if(typeof _fileName == 'undefined')
-		throw "_fileName is undefined.";
-	else if(Object.prototype.toString.call(_fileName) == "[object String]")
-			var fileName = _fileName;
-	else
-		throw "illegal argument _fileName.";
-	
+	var fileName = _fileName;
 	
 	//the communicator to the actual bookmark store.
-	if(typeof _comm == 'undefined')
-		throw "_comm is undefined.";
-	else if(Object.prototype.toString.call(_comm) == "[object Communicator]")
-		var comm = _comm;
-	else
-		throw "illegal argument _comm.";
-	
+	var comm = _comm;
 	
 	//the crypto layer object to en/decrypt the bookmark file.
-	if(typeof _bookmarkCrypto == 'undefined')
-		throw "_bookmarkCrypto is undefined.";
-	else if(Object.prototype.toString.call(_bookmarkCrypto) == "[object BookmarkCrypto]")
-		var bookmarkCrypto = _bookmarkCrypto;
-	else
-		throw "illegal argument _bookmarkCrypto.";
-	
+	var bookmarkCrypto = _bookmarkCrypto;
 	
 	//the in-memory bookmark store
 	var bookmarks = new Array();
 	
 	
-	
 	/* ************************
 	 * * Functions
 	 * ************************/
 	 **/
 	this.setFileName = function(_fileName) {
 		
-		if(typeof _fileName == 'undefined')
-			throw "_fileName is undefined.";
-		else if(Object.prototype.toString.call(_fileName) == "[object String]")
-			fileName = _fileName;
-		else
-			throw "illegal argument _fileName.";
+		fileName = _fileName;
 	};
 	
 	
 	 **/
 	this.setComm = function(_comm) {
 		
-		if(typeof _comm == 'undefined')
-			throw "_comm is undefined.";
-		else if(Object.prototype.toString.call(_comm) == "[object Communicator]")
-			comm = _comm;
-		else
-			throw "illegal argument _comm.";
+		comm = _comm;
 	};
 	
 	
 	 **/
 	this.setBookmarkCrypto = function(_bookmarkCrypto) {
 		
-		if(typeof _bookmarkCrypto == 'undefined')
-			throw "_bookmarkCrypto is undefined.";
-		else if(Object.prototype.toString.call(_bookmarkCrypto) == "[object BookmarkCrypto]")
-			bookmarkCrypto = _bookmarkCrypto;
-		else
-			throw "illegal argument _bookmarkCrypto.";
+		bookmarkCrypto = _bookmarkCrypto;
 	};
 };

File src/main/client/domain/Bookmark.js

 
 
 /**
- * new Bookmark(String, String[, Array = [], Array = [] ])
- *
- * TODO ensure that tag and meta arrays contain only strings?!
- * TODO its improtant to make a utility function that checks function
- * parameters to reduce redundant code for checking in constructr and setters...
- * i.e. checkParam(param, acceptedTypes, defaultValue)
+ * new Bookmark(String, String[, Array[, Array]])
  *
  * **_title** the title of the bookmark (i.e. the page's title)
  * **_url** the page url
 	 * ************************/
 	
 	//title of the link, i.e. the page title
-	if(typeof _title == 'undefined')
-		throw "_title is undefined.";
-	else if(Object.prototype.toString.call(_title) == "[object String]")
-		var title = _title;
-	else
-		throw "illegal argument _title.";
+	var title = _title;
 	
-
 	//url to a webpage
-	if(typeof _url == 'undefined')
-		throw "_url is undefined.";
-	else if(Object.prototype.toString.call(_url) == "[object String]")
-		var url = _url;
-	else
-		throw "illegal argument _url.";
+	var url = _url;
 	
-
 	//the associated tags
-	if(typeof _tags == 'undefined')
-		var tags = new Array();
-	else if(Object.prototype.toString.call(_tags) == "[object Array]")
-		var tags = _tags;
-	else
-		throw "illegal argument _tags.";
-
-
+	var tags = _tags;
+	
 	//the webpage's meta tags
-	if(typeof _metas == 'undefined')
-		var metas = new Array();
-	else if(Object.prototype.toString.call(_metas) == "[object Array]")
-		var metas = _metas;
-	else
-		throw "illegal argument _metas.";
-
-
-
+	var metas = _metas;
+	
+	
 	/* ************************
-     * * Functions
-     * ************************/
-
+	 * * Functions
+	 * ************************/
+	
 	/**
 	 * Bookmark#addTag(String)
 	 *
 	 **/
 	this.setTitle = function(_title) {
 		
-		if(typeof _title == 'undefined')
-			throw "_title is undefined.";
-		else if(Object.prototype.toString.call(_title) == "[object String]")
-			title = _title;
-		else
-			throw "illegal argument _title.";
+		title = _title;
 	};
 
 	/**
 	 **/
 	this.setUrl = function(_url) {
 		
-		if(typeof _url == 'undefined')
-			throw "_url is undefined.";
-		else if(Object.prototype.toString.call(_url) == "[object String]")
-			url = _url;
-		else
-			throw "illegal argument _url.";
+		url = _url;
 	};
 
 	/**
 	 **/
 	this.setTags = function(_tags) {
 		
-		if(typeof _tags == 'undefined')
-			throw "_tags is undefined.";
-		else if(Object.prototype.toString.call(_tags) == "[object Array]")		
-			tags = _tags;
-		else
-			throw "illegal argument _tags.";
+		tags = _tags;
 	};
 
 	/**
 	 **/
 	this.setMetas = function(_metas) {
 		
-		if(typeof _metas == 'undefined')
-			throw "_metas is undefined.";
-		else if(Object.prototype.toString.call(_metas) == "[object Array]")
-			metas = _metas;
-		else
-			throw "illegal argument _metas.";
+		metas = _metas;
 	};
 
 

File src/main/client/util/Settings.js

  **/
 bookmaak.util.addSetting = function(_login, _key, _value, _type){
 	
-	if(typeof _login == 'undefined')
-		throw "_login is undefined.";
-	else if(Object.prototype.toString.call(_login) == "[object String]")
-			var login = _login;
-	else
-		throw "illegal argument _login.";
+	var login = _login;
 	
-	if(typeof _key == 'undefined')
-		throw "_key is undefined.";
-	else if(Object.prototype.toString.call(_key) == "[object String]") {
-		//check _key
-		switch(_key) {
-			case bookmaak.util.SETTING_KEY.LOGIN:
-			case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
-			case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
-				var key = _key;
-				break;
-			default:
-				throw "illegal key.";
-		}
+	//check _key
+	switch(_key) {
+		case bookmaak.util.SETTING_KEY.LOGIN:
+		case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
+		case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
+			var key = _key;
+			break;
+		default:
+			throw "illegal key.";
 	}
-	else
-		throw "illegal argument _key.";
 	
-	if(typeof _type == 'undefined')
-		throw "_type is undefined.";
-	else if(Object.prototype.toString.call(_type) == "[object String]") {
-		//check _type
-		switch(_type) {
-			case bookmaak.util.SETTING_TYPE.USER:
-			case bookmaak.util.SETTING_TYPE.GLOBAL:
-				var type = _type;
-				break;
-			default:
-				throw "illegal type.";
-		}
+	//check _type
+	switch(_type) {
+		case bookmaak.util.SETTING_TYPE.USER:
+		case bookmaak.util.SETTING_TYPE.GLOBAL:
+			var type = _type;
+			break;
+		default:
+			throw "illegal type.";
 	}
-	else
-		throw "illegal argument _type.";
 	
-	if(typeof _value == 'undefined')
-		throw "_value is undefined.";
-	else
-		var value = _value;
+	var value = _value;
 	
 	return addSetting(type, key+"_"+login, value);
 };
  **/
 bookmaak.util.getSetting = function(_login, _key, _type) {
 	
-	if(typeof _login == 'undefined')
-		throw "_login is undefined.";
-	else if(Object.prototype.toString.call(_login) == "[object String]")
-			var login = _login;
-	else
-		throw "illegal argument _login.";
+	var login = _login;
 	
-	if(typeof _key == 'undefined')
-		throw "_key is undefined.";
-	else if(Object.prototype.toString.call(_key) == "[object String]") {
-		//check _key
-		switch(_key) {
-			case bookmaak.util.SETTING_KEY.LOGIN:
-			case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
-			case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
-				var key = _key;
-				break;
-			default:
-				throw "illegal key.";
-		}
+	//check _key
+	switch(_key) {
+		case bookmaak.util.SETTING_KEY.LOGIN:
+		case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
+		case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
+			var key = _key;
+			break;
+		default:
+			throw "illegal key.";
 	}
-	else
-		throw "illegal argument _key.";
 	
-	if(typeof _type == 'undefined')
-		throw "_type is undefined.";
-	else if(Object.prototype.toString.call(_type) == "[object String]") {
-		//check _type
-		switch(_type) {
-			case bookmaak.util.SETTING_TYPE.USER:
-			case bookmaak.util.SETTING_TYPE.GLOBAL:
-				var type = _type;
-				break;
-			default:
-				throw "illegal type.";
-		}
+	//check _type
+	switch(_type) {
+		case bookmaak.util.SETTING_TYPE.USER:
+		case bookmaak.util.SETTING_TYPE.GLOBAL:
+			var type = _type;
+			break;
+		default:
+			throw "illegal type.";
 	}
-	else
-		throw "illegal argument _type.";
-	
 	
 	return getSetting(type, key+"_"+login);
 	
  **/
 bookmaak.util.removeSetting = function(_login, _key, _type) {
 	
-	if(typeof _login == 'undefined')
-		throw "_login is undefined.";
-	else if(Object.prototype.toString.call(_login) == "[object String]")
-			var login = _login;
-	else
-		throw "illegal argument _login.";
+	var login = _login;
 	
-	if(typeof _key == 'undefined')
-		throw "_key is undefined.";
-	else if(Object.prototype.toString.call(_key) == "[object String]") {
-		//check _key
-		switch(_key) {
-			case bookmaak.util.SETTING_KEY.LOGIN:
-			case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
-			case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
-				var key = _key;
-				break;
-			default:
-				throw "illegal key.";
-		}
+	//check _key
+	switch(_key) {
+		case bookmaak.util.SETTING_KEY.LOGIN:
+		case bookmaak.util.SETTING_KEY.PRIVATE_KEY:
+		case bookmaak.util.SETTING_KEY.PUBLIC_KEY:
+			var key = _key;
+			break;
+		default:
+			throw "illegal key.";
 	}
-	else
-		throw "illegal argument _key.";
 	
-	if(typeof _type == 'undefined')
-		throw "_type is undefined.";
-	else if(Object.prototype.toString.call(_type) == "[object String]") {
-		//check _type
-		switch(_type) {
-			case bookmaak.util.SETTING_TYPE.USER:
-			case bookmaak.util.SETTING_TYPE.GLOBAL:
-				var type = _type;
-				break;
-			default:
-				throw "illegal type.";
-		}
+	//check _type
+	switch(_type) {
+		case bookmaak.util.SETTING_TYPE.USER:
+		case bookmaak.util.SETTING_TYPE.GLOBAL:
+			var type = _type;
+			break;
+		default:
+			throw "illegal type.";
 	}
-	else
-		throw "illegal argument _type.";
 	
 	//remove the key
 	return removeSetting(type, key+"_"+login);