Bug 1882457 - Update the release process docs for the monorepo migration. r=ahal...
[gecko.git] / security / nss / cpputil / tls_parser.cc
blobefedd7a658758233418809aeebf34a92befff230
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "tls_parser.h"
9 namespace nss_test {
11 bool TlsParser::Read(uint8_t* val) {
12 if (remaining() < 1) {
13 return false;
15 *val = *ptr();
16 consume(1);
17 return true;
20 bool TlsParser::Read(uint32_t* val, size_t size) {
21 if (size > sizeof(uint32_t)) {
22 return false;
25 uint32_t v = 0;
26 for (size_t i = 0; i < size; ++i) {
27 uint8_t tmp;
28 if (!Read(&tmp)) {
29 return false;
32 v = (v << 8) | tmp;
35 *val = v;
36 return true;
39 bool TlsParser::Read(DataBuffer* val, size_t len) {
40 if (remaining() < len) {
41 return false;
44 val->Assign(ptr(), len);
45 consume(len);
46 return true;
49 bool TlsParser::ReadFromMark(DataBuffer* val, size_t len, size_t mark) {
50 auto saved = offset_;
51 offset_ = mark;
53 if (remaining() < len) {
54 offset_ = saved;
55 return false;
58 val->Assign(ptr(), len);
60 offset_ = saved;
61 return true;
64 bool TlsParser::ReadVariable(DataBuffer* val, size_t len_size) {
65 uint32_t len;
66 if (!Read(&len, len_size)) {
67 return false;
69 return Read(val, len);
72 bool TlsParser::Skip(size_t len) {
73 if (len > remaining()) {
74 return false;
76 consume(len);
77 return true;
80 bool TlsParser::SkipVariable(size_t len_size) {
81 uint32_t len;
82 if (!Read(&len, len_size)) {
83 return false;
85 return Skip(len);
88 } // namespace nss_test