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 | |
| 7 | if( typeof _pkd == "ByteArray") this.PublisherPublicKeyDigest = _pkd; // Byte Array |
| 8 | else if( typeof _pkd == "PublicKey") ;//TODO... |
| 9 | |
| 10 | }; |
| 11 | |
| 12 | PublisherPublicKeyDigest.prototype.decode = function( decoder) { |
| 13 | |
| 14 | this.PublisherPublicKeyDigest = decoder.readBinaryElement(this.getElementLabel()); |
| 15 | if (null == this.PublisherPublicKeyDigest) { |
| 16 | throw new Exception("Cannot parse publisher key digest."); |
| 17 | } |
| 18 | |
| 19 | //TODO check if the length of the PublisherPublicKeyDigest is correct ( Security reason) |
| 20 | |
| 21 | /*if (this.PublisherPublicKeyDigest.length != PublisherID.PUBLISHER_ID_LEN) { |
| 22 | console.log('SHOULD NOT GO HERE !!!!!!!!!!!!!!!!!!'); |
| 23 | this.PublisherPublicKeyDigest = new PublisherPublicKeyDigest(this.PublisherPublicKeyDigest).PublisherKeyDigest; |
| 24 | }*/ |
| 25 | }; |
| 26 | |
| 27 | PublisherPublicKeyDigest.prototype.encode= function( encoder) { |
| 28 | //TODO Check that the ByteArray for the key is present |
| 29 | /*if (!this.validate()) { |
| 30 | throw new Exception("Cannot encode : field values missing."); |
| 31 | }*/ |
| 32 | |
| 33 | if (this.PublisherKeyDigest!=null)this.encoder.writeElement(this.getElementLabel(), this.PublisherKeyDigest); |
| 34 | }; |
| 35 | |
| 36 | PublisherPublicKeyDigest.prototype.getElementLabel = function() { return CCNProtocolDTags.PublisherPublicKeyDigest; }; |
| 37 | |
| 38 | PublisherPublicKeyDigest.prototype.validate =function() { |
| 39 | return (null != this.PublisherKeyDigest); |
| 40 | }; |