/src/nss/fuzz/targets/lib/tls/socket.cc
Line | Count | Source |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include "socket.h" |
6 | | |
7 | | #include <algorithm> |
8 | | #include <cassert> |
9 | | #include <cstdint> |
10 | | #include <cstring> |
11 | | |
12 | | #include "prinrval.h" |
13 | | #include "prio.h" |
14 | | |
15 | | namespace TlsSocket { |
16 | | |
17 | 2.43M | int32_t DummyPrSocket::Read(PRFileDesc *fd, void *data, int32_t len) { |
18 | 2.43M | assert(data && len > 0); |
19 | | |
20 | 2.43M | int32_t amount = std::min(len, static_cast<int32_t>(len_)); |
21 | 2.43M | memcpy(data, buf_, amount); |
22 | | |
23 | 2.43M | buf_ += amount; |
24 | 2.43M | len_ -= amount; |
25 | | |
26 | 2.43M | return amount; |
27 | 2.43M | } |
28 | | |
29 | 290k | int32_t DummyPrSocket::Write(PRFileDesc *fd, const void *buf, int32_t length) { |
30 | 290k | return length; |
31 | 290k | } |
32 | | |
33 | | int32_t DummyPrSocket::Recv(PRFileDesc *fd, void *buf, int32_t buflen, |
34 | 2.43M | int32_t flags, PRIntervalTime to) { |
35 | 2.43M | assert(flags == 0); |
36 | 2.43M | return Read(fd, buf, buflen); |
37 | 2.43M | } |
38 | | |
39 | | } // namespace TlsSocket |