Meki Cherkaoui | 97e7a59 | 2012-04-14 02:50:06 -0700 | [diff] [blame^] | 1 | |
| 2 | |
| 3 | var Signature = function Signature(_Witness,_Signature,_DigestAlgorithm) { |
| 4 | |
| 5 | this.Witness = _Witness;//byte [] _witness; |
| 6 | this.Signature = _Signature;//byte [] _signature; |
| 7 | this.DigestAlgorithm = _DigestAlgorithm//String _digestAlgorithm; |
| 8 | }; |
| 9 | |
| 10 | |
| 11 | Signature.prototype.decode =function( decoder) { |
| 12 | decoder.readStartElement(this.getElementLabel()); |
| 13 | if (decoder.peekStartElement(CCNProtocolDTags.DigestAlgorithm)) { |
| 14 | this.DigestAlgorithm = decoder.readUTF8Element(CCNProtocolDTags.DigestAlgorithm); |
| 15 | } |
| 16 | if (decoder.peekStartElement(CCNProtocolDTags.Witness)) { |
| 17 | this.Witness = decoder.readBinaryElement(CCNProtocolDTags.Witness); |
| 18 | } |
| 19 | this.Signature = decoder.readBinaryElement(CCNProtocolDTags.SignatureBits); |
| 20 | decoder.readEndElement(); |
| 21 | |
| 22 | }; |
| 23 | |
| 24 | |
| 25 | Signature.prototype.encode= function( encoder){ |
| 26 | |
| 27 | if (!this.validate()) { |
| 28 | throw new Exception("Cannot encode: field values missing."); |
| 29 | } |
| 30 | |
| 31 | encoder.writeStartElement(this.getElementLabel()); |
| 32 | |
| 33 | if ((null != this.DigestAlgorithm) && (!this.DigestAlgorithm.equals(CCNDigestHelper.DEFAULT_DIGEST_ALGORITHM))) { |
| 34 | encoder.writeElement(CCNProtocolDTags.DigestAlgorithm, OIDLookup.getDigestOID(this.DigestAlgorithm)); |
| 35 | } |
| 36 | |
| 37 | if (null != this.Witness) { |
| 38 | // needs to handle null witness |
| 39 | encoder.writeElement(CCNProtocolDTags.Witness, this.Witness); |
| 40 | } |
| 41 | |
| 42 | encoder.writeElement(CCNProtocolDTags.SignatureBits, this.Signature); |
| 43 | |
| 44 | encoder.writeEndElement(); |
| 45 | }; |
| 46 | |
| 47 | Signature.prototype.getElementLabel = function() { return CCNProtocolDTags.Signature; }; |
| 48 | |
| 49 | |
| 50 | Signature.prototype.validate = function() { |
| 51 | return null != this.Signature; |
| 52 | }; |
| 53 | |