def _make_token(self, username, expire_time): t = protocol.Token(username=username, valid_from=int(self.now_func() - CLOCK_FUDGE), valid_to=expire_time) b = t.serialize() payload = protocol.VerifiablePayload(digest=self._hmac(b), payload=b) return ssh.base64url_encode(payload.serialize())
def test_serialize_token_binary(): token = protocol.Token(valid_from=1365084334, valid_to=1365084634, username="******") buf = protocol.Token.serialize(token) assert buf == "t\x00\x00\x00Q]\x88\xaeQ]\x89\xda\x00\x00\x00\x03noa\x00"
# "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. import xdrlib from crtauth import protocol ref_token = protocol.Token(valid_from=1365084334, valid_to=1365084634, username="******") def test_serialize_token(): p = xdrlib.Packer() p.pack_fstring(1, protocol.Token.__magic__) p.pack_uint(ref_token.valid_from) p.pack_uint(ref_token.valid_to) p.pack_string(ref_token.username) buf = p.get_buffer() ref_buf = ref_token.serialize() assert buf == ref_buf