Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
Jeff Thompson | 745026e | 2012-10-13 12:49:20 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 4 | * This class represents PublisherPublicKeyDigest Objects |
| 5 | */ |
| 6 | var PublisherPublicKeyDigest = function PublisherPublicKeyDigest(_pkd){ |
| 7 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 8 | //this.PUBLISHER_ID_LEN = 256/8; |
| 9 | this.PUBLISHER_ID_LEN = 512/8; |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 10 | |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 11 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 12 | this.publisherPublicKeyDigest = _pkd; |
| 13 | //if( typeof _pkd == "object") this.publisherPublicKeyDigest = _pkd; // Byte Array |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 14 | //else if( typeof _pkd == "PublicKey") ;//TODO... |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 15 | |
| 16 | }; |
| 17 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 18 | PublisherPublicKeyDigest.prototype.from_ccnb = function( decoder) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 19 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 20 | this.publisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel()); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 22 | if(LOG>4)console.log('Publisher public key digest is ' + this.publisherPublicKeyDigest); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 23 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 24 | if (null == this.publisherPublicKeyDigest) { |
Jeff Thompson | 34a2ec0 | 2012-09-29 21:47:05 -0700 | [diff] [blame] | 25 | throw new Error("Cannot parse publisher key digest."); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason) |
| 29 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 30 | if (this.publisherPublicKeyDigest.length != this.PUBLISHER_ID_LEN) { |
Jeff Thompson | cf187ff | 2012-10-21 16:18:55 -0700 | [diff] [blame] | 31 | if (LOG > 0) |
| 32 | 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] | 33 | |
Jeff Thompson | cf187ff | 2012-10-21 16:18:55 -0700 | [diff] [blame] | 34 | //this.publisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest; |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 35 | } |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 38 | PublisherPublicKeyDigest.prototype.to_ccnb= function( encoder) { |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 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()) { |
Jeff Thompson | 34a2ec0 | 2012-09-29 21:47:05 -0700 | [diff] [blame] | 41 | throw new Error("Cannot encode : field values missing."); |
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 42 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -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() { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 50 | return (null != this.publisherPublicKeyDigest); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 51 | }; |