Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents PublisherPublicKeyDigest Objects |
| 4 | */ |
| 5 | var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){ |
| 6 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 7 | //this.PUBLISHER_ID_LEN = 256/8; |
| 8 | this.PUBLISHER_ID_LEN = 512/8; |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 9 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 10 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 11 | this.PublisherPublicKeyDigest = _pkd; |
| 12 | //if( typeof _pkd == "object") this.PublisherPublicKeyDigest = _pkd; // Byte Array |
| 13 | //else if( typeof _pkd == "PublicKey") ;//TODO... |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 14 | |
| 15 | }; |
| 16 | |
| 17 | PublisherPublicKeyDigest.prototype.decode = function( decoder) { |
| 18 | |
| 19 | this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel()); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 20 | |
| 21 | if(LOG>4)console.log('Publisher public key digest is ' + this.PublisherPublicKeyDigest); |
| 22 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 23 | 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 Thompson | f14b7bc | 2012-09-23 16:17:13 -0700 | [diff] [blame^] | 29 | if (this.PublisherPublicKeyDigest.length != this.PUBLISHER_ID_LEN) { |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 30 | |
Jeff Thompson | f14b7bc | 2012-09-23 16:17:13 -0700 | [diff] [blame^] | 31 | console.log('LENGTH OF PUBLISHER ID IS WRONG! Expected ' + this.PUBLISHER_ID_LEN + ", got " + this.PublisherPublicKeyDigest.length); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 32 | |
| 33 | //this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest; |
| 34 | |
| 35 | } |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | PublisherPublicKeyDigest.prototype.encode= function( encoder) { |
| 39 | //TODO Check that the ByteArray for the key is present |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 40 | if (!this.validate()) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 41 | throw new Exception("Cannot encode : field values missing."); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 42 | } |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 43 | if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.PublisherPublicKeyDigest); |
| 44 | encoder.writeElement(this.getElementLabel(), this.PublisherPublicKeyDigest); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; }; |
| 48 | |
| 49 | PublisherPublicKeyDigest.prototype.validate =function() { |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 50 | return (null != this.PublisherPublicKeyDigest); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 51 | }; |