blob: a5b400d60b1f339b00bb719d6f42141a759adcc6 [file] [log] [blame]
Meki Cherkaouif441d3a2012-04-22 15:17:52 -07001/*
2 * @author: ucla-cs
3 * This class represents PublisherPublicKeyDigest Objects
4 */
5var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){
6
Meki Cherkaoui8f173612012-06-06 01:05:40 -07007 //this.PUBLISHER_ID_LEN = 256/8;
8 this.PUBLISHER_ID_LEN = 512/8;
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07009
Meki Cherkaoui8f173612012-06-06 01:05:40 -070010
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070011 this.PublisherPublicKeyDigest = _pkd;
12 //if( typeof _pkd == "object") this.PublisherPublicKeyDigest = _pkd; // Byte Array
13 //else if( typeof _pkd == "PublicKey") ;//TODO...
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070014
15};
16
17PublisherPublicKeyDigest.prototype.decode = function( decoder) {
18
19 this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel());
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070020
21 if(LOG>4)console.log('Publisher public key digest is ' + this.PublisherPublicKeyDigest);
22
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070023 if (null == this.PublisherPublicKeyDigest) {
24 throw new Exception("Cannot parse publisher key digest.");
25 }
26
27 //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason)
28
Jeff Thompsonf14b7bc2012-09-23 16:17:13 -070029 if (this.PublisherPublicKeyDigest.length != this.PUBLISHER_ID_LEN) {
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070030
Jeff Thompsonf14b7bc2012-09-23 16:17:13 -070031 console.log('LENGTH OF PUBLISHER ID IS WRONG! Expected ' + this.PUBLISHER_ID_LEN + ", got " + this.PublisherPublicKeyDigest.length);
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070032
33 //this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest;
34
35 }
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070036 };
37
38PublisherPublicKeyDigest.prototype.encode= function( encoder) {
39 //TODO Check that the ByteArray for the key is present
Meki Cherkaoui8f173612012-06-06 01:05:40 -070040 if (!this.validate()) {
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070041 throw new Exception("Cannot encode : field values missing.");
Meki Cherkaoui8f173612012-06-06 01:05:40 -070042 }
Meki Cherkaouif3d8f692012-05-18 15:44:28 -070043 if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.PublisherPublicKeyDigest);
44 encoder.writeElement(this.getElementLabel(), this.PublisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070045};
46
47PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; };
48
49PublisherPublicKeyDigest.prototype.validate =function() {
Meki Cherkaoui8f173612012-06-06 01:05:40 -070050 return (null != this.PublisherPublicKeyDigest);
Meki Cherkaouif441d3a2012-04-22 15:17:52 -070051};