summaryrefslogtreecommitdiff
path: root/implementation/protocol/src/remove_security_policy_command.cpp
blob: acf8aeda92f6158f92cb3521df6668d6ef9ce497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (C) 2021 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <limits>

#include "../include/remove_security_policy_command.hpp"
#include "../../security/include/policy.hpp"

namespace vsomeip_v3 {
namespace protocol {

remove_security_policy_command::remove_security_policy_command()
    : command(id_e::REMOVE_SECURITY_POLICY_ID) {
}

void
remove_security_policy_command::serialize(std::vector<byte_t> &_buffer,
        error_e &_error) const {

    size_t its_size(COMMAND_HEADER_SIZE + sizeof(update_id_)
            + sizeof(uid_) + sizeof(gid_));

    if (its_size > std::numeric_limits<command_size_t>::max()) {

        _error = error_e::ERROR_MAX_COMMAND_SIZE_EXCEEDED;
        return;
    }

    // resize buffer
    _buffer.resize(its_size);

    // set size
    size_ = static_cast<command_size_t>(its_size - COMMAND_HEADER_SIZE);

    // serialize header
    command::serialize(_buffer, _error);
    if (_error != error_e::ERROR_OK)
        return;

    // serialize payload
    size_t its_offset(COMMAND_HEADER_SIZE);
    std::memcpy(&_buffer[its_offset], &update_id_, sizeof(update_id_));
    its_offset += sizeof(update_id_);
    std::memcpy(&_buffer[its_offset], &uid_, sizeof(uid_));
    its_offset += sizeof(uid_);
    std::memcpy(&_buffer[its_offset], &gid_, sizeof(gid_));
}

void
remove_security_policy_command::deserialize(const std::vector<byte_t> &_buffer,
        error_e &_error) {

    if (COMMAND_HEADER_SIZE + sizeof(update_id_)
            + sizeof(uid_) + sizeof(gid_t) > _buffer.size()) {

        _error = error_e::ERROR_NOT_ENOUGH_BYTES;
        return;
    }

    // deserialize header
    command::deserialize(_buffer, _error);
    if (_error != error_e::ERROR_OK)
        return;

    // deserialize payload
    size_t its_offset(COMMAND_HEADER_SIZE);
    std::memcpy(&update_id_, &_buffer[its_offset], sizeof(update_id_));
    its_offset += sizeof(update_id_);
    std::memcpy(&uid_, &_buffer[its_offset], sizeof(uid_));
    its_offset += sizeof(uid_);
    std::memcpy(&gid_, &_buffer[its_offset], sizeof(gid_));
}

uint32_t
remove_security_policy_command::get_update_id() const {

    return (update_id_);
}

void
remove_security_policy_command::set_update_id(uint32_t _update_id) {

    update_id_ = _update_id;
}


uid_t
remove_security_policy_command::get_uid() const {

    return (uid_);
}

void
remove_security_policy_command::set_uid(uid_t _uid) {

    uid_ = _uid;
}

gid_t
remove_security_policy_command::get_gid() const {

    return (gid_);
}

void
remove_security_policy_command::set_gid(gid_t _gid) {

    gid_ = _gid;
}

} // namespace protocol
} // namespace vsomeip