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 | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 7 | |
| 8 | this.PUBLISHER_ID_LEN = 256/8; |
| 9 | |
| 10 | this.PublisherPublicKeyDigest = _pkd; |
| 11 | //if( typeof _pkd == "object") this.PublisherPublicKeyDigest = _pkd; // Byte Array |
| 12 | //else if( typeof _pkd == "PublicKey") ;//TODO... |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 13 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 14 | |
| 15 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 16 | }; |
| 17 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 18 | |
| 19 | |
| 20 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 21 | PublisherPublicKeyDigest.prototype.decode = function( decoder) { |
| 22 | |
| 23 | this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel()); |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 24 | |
| 25 | if(LOG>4)console.log('Publisher public key digest is ' + this.PublisherPublicKeyDigest); |
| 26 | |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 27 | if (null == this.PublisherPublicKeyDigest) { |
| 28 | throw new Exception("Cannot parse publisher key digest."); |
| 29 | } |
| 30 | |
| 31 | //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason) |
| 32 | |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 33 | if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) { |
| 34 | |
| 35 | console.log('LENGTH OF PUBLISHER ID IS WRONG!'); |
| 36 | |
| 37 | //this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest; |
| 38 | |
| 39 | } |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | PublisherPublicKeyDigest.prototype.encode= function( encoder) { |
| 43 | //TODO Check that the ByteArray for the key is present |
| 44 | /*if (!this.validate()) { |
| 45 | throw new Exception("Cannot encode : field values missing."); |
| 46 | }*/ |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 47 | if(LOG>3) console.log('PUBLISHER KEY DIGEST IS'+this.PublisherPublicKeyDigest); |
| 48 | encoder.writeElement(this.getElementLabel(), this.PublisherPublicKeyDigest); |
Meki Cherkaoui | f441d3a | 2012-04-22 15:17:52 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; }; |
| 52 | |
| 53 | PublisherPublicKeyDigest.prototype.validate =function() { |
| 54 | return (null != this.PublisherKeyDigest); |
| 55 | }; |