summaryrefslogtreecommitdiff
path: root/src/tag.rs
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2018-02-23 14:34:43 -0500
committerAaron Hill <aa1ronham@gmail.com>2018-03-01 19:47:05 -0500
commit5abdc895985ed24544b923495250611292e088a7 (patch)
tree97750afb078fd24abac6bd5d544cc65722dd9639 /src/tag.rs
parent7d450312743556696c58d2779f94e482ab7ccb9a (diff)
downloadroughenough-5abdc895985ed24544b923495250611292e088a7.zip
Add client implementation
Diffstat (limited to 'src/tag.rs')
-rw-r--r--src/tag.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/tag.rs b/src/tag.rs
index 05e5da9..4ec02b0 100644
--- a/src/tag.rs
+++ b/src/tag.rs
@@ -12,8 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+use error::Error;
+
/// An unsigned 32-bit value (key) that maps to a byte-string (value).
-#[derive(Debug, PartialEq, PartialOrd)]
+#[derive(Debug, PartialEq, Eq, PartialOrd, Hash, Clone)]
pub enum Tag {
// Enforcement of the "tags in strictly increasing order" rule is done using the
// little-endian encoding of the ASCII tag value; e.g. 'SIG\x00' is 0x00474953 and
@@ -56,4 +58,24 @@ impl Tag {
Tag::SREP => b"SREP",
}
}
+
+ pub fn from_wire(bytes: &[u8]) -> Result<Self, Error> {
+ match bytes {
+ b"CERT" => Ok(Tag::CERT),
+ b"DELE" => Ok(Tag::DELE),
+ b"INDX" => Ok(Tag::INDX),
+ b"MAXT" => Ok(Tag::MAXT),
+ b"MIDP" => Ok(Tag::MIDP),
+ b"MINT" => Ok(Tag::MINT),
+ b"NONC" => Ok(Tag::NONC),
+ b"PAD\xff" => Ok(Tag::PAD),
+ b"PATH" => Ok(Tag::PATH),
+ b"PUBK" => Ok(Tag::PUBK),
+ b"RADI" => Ok(Tag::RADI),
+ b"ROOT" => Ok(Tag::ROOT),
+ b"SIG\x00" => Ok(Tag::SIG),
+ b"SREP" => Ok(Tag::SREP),
+ _ => Err(Error::InvalidTag(Box::from(bytes)))
+ }
+ }
}