Diff
Not logged in

Differences From Artifact [c3b34b64e6]:

To Artifact [62e56d35f1]:


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86







87
88
89
90
91
92
93
..
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
...
252
253
254
255
256
257
258







259
260
261
262
263
264
265
266
267
268
269
270
271






272
273
274
275
276
277
278
...
306
307
308
309
310
311
312






313
314
315
            memcmp(this, other)
        }
    }
    impl ::std::cmp::Eq for $newtype {}

    #[cfg(feature = "serde")]
    impl ::serde::Serialize for $newtype {
        fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
            where S: ::serde::Serializer
        {
            serializer.serialize_bytes(&self[..])
        }
    }

    #[cfg(feature = "rustc-serialize")]
    impl rustc_serialize::Encodable for $newtype {
        fn encode<E: rustc_serialize::Encoder>(&self, encoder: &mut E)
                -> Result<(), E::Error> {
            encoder.emit_seq($len, |encoder| {
                for (i, e) in self[..].iter().enumerate() {
                    try!(encoder.emit_seq_elt(i, |encoder| e.encode(encoder)))
                }
                Ok(())
            })
        }
    }

    #[cfg(feature = "serde")]
    impl ::serde::Deserialize for $newtype {
        fn deserialize<D>(deserializer: &mut D) -> Result<$newtype, D::Error>
            where D: ::serde::Deserializer
        {
            struct NewtypeVisitor;
            impl ::serde::de::Visitor for NewtypeVisitor {
                type Value = $newtype;



                fn visit_seq<V>(&mut self, mut _visitor: V) -> Result<Self::Value, V::Error>
                    where V: ::serde::de::SeqVisitor
                {
                    let mut res = $newtype([0; $len]);
                    {
                        let $newtype(ref mut arr) = res;
                        for r in arr.iter_mut() {
                            match try!(_visitor.visit()) {
                                None => return Err(::serde::de::Error::end_of_stream()),
                                Some(value) => *r = value
                            }
                        }
                    }
                    try!(_visitor.end());
                    Ok(res)
                }







            }
            deserializer.deserialize_bytes(NewtypeVisitor)
        }
    }

    #[cfg(feature = "rustc-serialize")]
    impl rustc_serialize::Decodable for $newtype {
................................................................................
                        &format!("Expecting array of length: {}, but found {}",
                                 $len, len)));
                }
                let mut res = $newtype([0; $len]);
                {
                    let $newtype(ref mut arr) = res;
                    for (i, val) in arr.iter_mut().enumerate() {
                        *val = try!(decoder.read_seq_elt(i,
                            |decoder| rustc_serialize::Decodable::decode(decoder)));
                    }
                }
                Ok(res)
            })
        }
    }

................................................................................
    impl ::std::ops::Index<::std::ops::RangeFull> for $newtype {
        type Output = [u8];
        fn index(&self, _index: ::std::ops::RangeFull) -> &[u8] {
            let &$newtype(ref b) = self;
            b.index(_index)
        }
    }
    impl ::std::fmt::Debug for $newtype  {
        fn fmt(&self,
               formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            write!(formatter, "{}({:?})", stringify!($newtype), &self[..])
        }
    }
    ));

macro_rules! public_newtype_traits (($newtype:ident) => (
    impl AsRef<[u8]> for $newtype {
        #[inline]
        fn as_ref(&self) -> &[u8] {
            &self[..]
................................................................................
        impl Drop for $name {
            fn drop(&mut self) {
                use utils::memzero;
                let &mut $name(ref mut v) = self;
                memzero(v);
            }
        }







        );
    ( $(#[$meta:meta])*
      public $name:ident($bytes:expr);
      ) => (
        $(#[$meta])*
        #[derive(Copy)]
        #[must_use]
        pub struct $name(pub [u8; $bytes]);
        newtype_clone!($name);
        newtype_traits!($name, $bytes);
        public_newtype_traits!($name);
        impl $name {
            newtype_from_slice!($name, $bytes);






        }
        );
    ( $(#[$meta:meta])*
      nonce $name:ident($bytes:expr);
      ) => (
        $(#[$meta])*
        #[derive(Copy)]
................................................................................
            /// will not uphold any security guarantees.
            pub fn increment_le_inplace(&mut self) {
                use utils::increment_le;
                let &mut $name(ref mut r) = self;
                increment_le(r);
            }







        }
        );
}







|












|







|
|
|


|

>
>
>
|
|





|
<
|



<


>
>
>
>
>
>
>







 







|
|







 







<
<
<
<
<
<







 







>
>
>
>
>
>
>













>
>
>
>
>
>







 







>
>
>
>
>
>



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81

82
83
84
85

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
168
169
170
171
172
173
174






175
176
177
178
179
180
181
...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
            memcmp(this, other)
        }
    }
    impl ::std::cmp::Eq for $newtype {}

    #[cfg(feature = "serde")]
    impl ::serde::Serialize for $newtype {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
            where S: ::serde::Serializer
        {
            serializer.serialize_bytes(&self[..])
        }
    }

    #[cfg(feature = "rustc-serialize")]
    impl rustc_serialize::Encodable for $newtype {
        fn encode<E: rustc_serialize::Encoder>(&self, encoder: &mut E)
                -> Result<(), E::Error> {
            encoder.emit_seq($len, |encoder| {
                for (i, e) in self[..].iter().enumerate() {
                    (encoder.emit_seq_elt(i, |encoder| e.encode(encoder)))?
                }
                Ok(())
            })
        }
    }

    #[cfg(feature = "serde")]
    impl<'de> ::serde::Deserialize<'de> for $newtype {
        fn deserialize<D>(deserializer: D) -> Result<$newtype, D::Error>
            where D: ::serde::Deserializer<'de>
        {
            struct NewtypeVisitor;
            impl<'de> ::serde::de::Visitor<'de> for NewtypeVisitor {
                type Value = $newtype;
                fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    write!(formatter, stringify!($newtype))
                }
                fn visit_seq<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
                    where V: ::serde::de::SeqAccess<'de>
                {
                    let mut res = $newtype([0; $len]);
                    {
                        let $newtype(ref mut arr) = res;
                        for r in arr.iter_mut() {
                            if let Some(value) = (visitor.next_element())? {

                                *r = value;
                            }
                        }
                    }

                    Ok(res)
                }

                fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
                    where E: ::serde::de::Error
                {
                    $newtype::from_slice(v).ok_or(::serde::de::Error::invalid_length(v.len(),
                                                                                     &self))
                }
            }
            deserializer.deserialize_bytes(NewtypeVisitor)
        }
    }

    #[cfg(feature = "rustc-serialize")]
    impl rustc_serialize::Decodable for $newtype {
................................................................................
                        &format!("Expecting array of length: {}, but found {}",
                                 $len, len)));
                }
                let mut res = $newtype([0; $len]);
                {
                    let $newtype(ref mut arr) = res;
                    for (i, val) in arr.iter_mut().enumerate() {
                        *val = (decoder.read_seq_elt(i,
                            |decoder| rustc_serialize::Decodable::decode(decoder)))?;
                    }
                }
                Ok(res)
            })
        }
    }

................................................................................
    impl ::std::ops::Index<::std::ops::RangeFull> for $newtype {
        type Output = [u8];
        fn index(&self, _index: ::std::ops::RangeFull) -> &[u8] {
            let &$newtype(ref b) = self;
            b.index(_index)
        }
    }






    ));

macro_rules! public_newtype_traits (($newtype:ident) => (
    impl AsRef<[u8]> for $newtype {
        #[inline]
        fn as_ref(&self) -> &[u8] {
            &self[..]
................................................................................
        impl Drop for $name {
            fn drop(&mut self) {
                use utils::memzero;
                let &mut $name(ref mut v) = self;
                memzero(v);
            }
        }
        impl ::std::fmt::Debug for $name {
            fn fmt(&self,
                   formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                // Hide secrets from debug output.
                write!(formatter, "{}(****)", stringify!($name))
            }
        }
        );
    ( $(#[$meta:meta])*
      public $name:ident($bytes:expr);
      ) => (
        $(#[$meta])*
        #[derive(Copy)]
        #[must_use]
        pub struct $name(pub [u8; $bytes]);
        newtype_clone!($name);
        newtype_traits!($name, $bytes);
        public_newtype_traits!($name);
        impl $name {
            newtype_from_slice!($name, $bytes);
        }
        impl ::std::fmt::Debug for $name {
            fn fmt(&self,
                   formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                write!(formatter, "{}({:?})", stringify!($name), &self[..])
            }
        }
        );
    ( $(#[$meta:meta])*
      nonce $name:ident($bytes:expr);
      ) => (
        $(#[$meta])*
        #[derive(Copy)]
................................................................................
            /// will not uphold any security guarantees.
            pub fn increment_le_inplace(&mut self) {
                use utils::increment_le;
                let &mut $name(ref mut r) = self;
                increment_le(r);
            }

        }
        impl ::std::fmt::Debug for $name {
            fn fmt(&self,
                   formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                write!(formatter, "{}({:?})", stringify!($name), &self[..])
            }
        }
        );
}