Ram Gandikota
/
ABCD
A metronome using the FRDM K64F board
mbed-client/test/mbedclient/utest/stub/m2msecurity_stub.cpp@0:a7a43371b306, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:40:18 2017 +0000
- Revision:
- 0:a7a43371b306
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a7a43371b306 | 1 | /* |
ram54288 | 0:a7a43371b306 | 2 | * Copyright (c) 2015 ARM Limited. All rights reserved. |
ram54288 | 0:a7a43371b306 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ram54288 | 0:a7a43371b306 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
ram54288 | 0:a7a43371b306 | 5 | * not use this file except in compliance with the License. |
ram54288 | 0:a7a43371b306 | 6 | * You may obtain a copy of the License at |
ram54288 | 0:a7a43371b306 | 7 | * |
ram54288 | 0:a7a43371b306 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
ram54288 | 0:a7a43371b306 | 9 | * |
ram54288 | 0:a7a43371b306 | 10 | * Unless required by applicable law or agreed to in writing, software |
ram54288 | 0:a7a43371b306 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
ram54288 | 0:a7a43371b306 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ram54288 | 0:a7a43371b306 | 13 | * See the License for the specific language governing permissions and |
ram54288 | 0:a7a43371b306 | 14 | * limitations under the License. |
ram54288 | 0:a7a43371b306 | 15 | */ |
ram54288 | 0:a7a43371b306 | 16 | #include "m2msecurity_stub.h" |
ram54288 | 0:a7a43371b306 | 17 | |
ram54288 | 0:a7a43371b306 | 18 | bool m2msecurity_stub::has_value; |
ram54288 | 0:a7a43371b306 | 19 | uint32_t m2msecurity_stub::int_value; |
ram54288 | 0:a7a43371b306 | 20 | uint32_t m2msecurity_stub::sec_mode; |
ram54288 | 0:a7a43371b306 | 21 | bool m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 22 | String *m2msecurity_stub::string_value; |
ram54288 | 0:a7a43371b306 | 23 | M2MResource* m2msecurity_stub::resource; |
ram54288 | 0:a7a43371b306 | 24 | |
ram54288 | 0:a7a43371b306 | 25 | void m2msecurity_stub::clear() |
ram54288 | 0:a7a43371b306 | 26 | { |
ram54288 | 0:a7a43371b306 | 27 | has_value = false; |
ram54288 | 0:a7a43371b306 | 28 | int_value = -1; |
ram54288 | 0:a7a43371b306 | 29 | bool_value = false; |
ram54288 | 0:a7a43371b306 | 30 | string_value = NULL; |
ram54288 | 0:a7a43371b306 | 31 | resource = NULL; |
ram54288 | 0:a7a43371b306 | 32 | } |
ram54288 | 0:a7a43371b306 | 33 | |
ram54288 | 0:a7a43371b306 | 34 | M2MSecurity::M2MSecurity(ServerType ser_type) |
ram54288 | 0:a7a43371b306 | 35 | : M2MObject("0", stringdup("0")), |
ram54288 | 0:a7a43371b306 | 36 | _server_type(ser_type), |
ram54288 | 0:a7a43371b306 | 37 | _server_instance(NULL) |
ram54288 | 0:a7a43371b306 | 38 | { |
ram54288 | 0:a7a43371b306 | 39 | } |
ram54288 | 0:a7a43371b306 | 40 | |
ram54288 | 0:a7a43371b306 | 41 | M2MSecurity::~M2MSecurity() |
ram54288 | 0:a7a43371b306 | 42 | { |
ram54288 | 0:a7a43371b306 | 43 | } |
ram54288 | 0:a7a43371b306 | 44 | |
ram54288 | 0:a7a43371b306 | 45 | M2MResource* M2MSecurity::create_resource(SecurityResource, uint32_t) |
ram54288 | 0:a7a43371b306 | 46 | { |
ram54288 | 0:a7a43371b306 | 47 | return m2msecurity_stub::resource; |
ram54288 | 0:a7a43371b306 | 48 | } |
ram54288 | 0:a7a43371b306 | 49 | |
ram54288 | 0:a7a43371b306 | 50 | bool M2MSecurity::delete_resource(SecurityResource) |
ram54288 | 0:a7a43371b306 | 51 | { |
ram54288 | 0:a7a43371b306 | 52 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 53 | } |
ram54288 | 0:a7a43371b306 | 54 | |
ram54288 | 0:a7a43371b306 | 55 | bool M2MSecurity::set_resource_value(SecurityResource, |
ram54288 | 0:a7a43371b306 | 56 | const String &) |
ram54288 | 0:a7a43371b306 | 57 | { |
ram54288 | 0:a7a43371b306 | 58 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 59 | } |
ram54288 | 0:a7a43371b306 | 60 | |
ram54288 | 0:a7a43371b306 | 61 | bool M2MSecurity::set_resource_value(SecurityResource, |
ram54288 | 0:a7a43371b306 | 62 | uint32_t) |
ram54288 | 0:a7a43371b306 | 63 | { |
ram54288 | 0:a7a43371b306 | 64 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 65 | } |
ram54288 | 0:a7a43371b306 | 66 | |
ram54288 | 0:a7a43371b306 | 67 | bool M2MSecurity::set_resource_value(SecurityResource, |
ram54288 | 0:a7a43371b306 | 68 | const uint8_t *, |
ram54288 | 0:a7a43371b306 | 69 | const uint16_t) |
ram54288 | 0:a7a43371b306 | 70 | { |
ram54288 | 0:a7a43371b306 | 71 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 72 | } |
ram54288 | 0:a7a43371b306 | 73 | |
ram54288 | 0:a7a43371b306 | 74 | String M2MSecurity::resource_value_string(SecurityResource) const |
ram54288 | 0:a7a43371b306 | 75 | { |
ram54288 | 0:a7a43371b306 | 76 | return *m2msecurity_stub::string_value; |
ram54288 | 0:a7a43371b306 | 77 | } |
ram54288 | 0:a7a43371b306 | 78 | |
ram54288 | 0:a7a43371b306 | 79 | uint32_t M2MSecurity::resource_value_buffer(SecurityResource, |
ram54288 | 0:a7a43371b306 | 80 | uint8_t *&value) const |
ram54288 | 0:a7a43371b306 | 81 | { |
ram54288 | 0:a7a43371b306 | 82 | if( m2msecurity_stub::has_value ){ |
ram54288 | 0:a7a43371b306 | 83 | value = (uint8_t *)malloc(5); |
ram54288 | 0:a7a43371b306 | 84 | return 5; |
ram54288 | 0:a7a43371b306 | 85 | } |
ram54288 | 0:a7a43371b306 | 86 | return m2msecurity_stub::int_value; |
ram54288 | 0:a7a43371b306 | 87 | } |
ram54288 | 0:a7a43371b306 | 88 | |
ram54288 | 0:a7a43371b306 | 89 | uint32_t M2MSecurity::resource_value_buffer(SecurityResource, |
ram54288 | 0:a7a43371b306 | 90 | const uint8_t *&value) const |
ram54288 | 0:a7a43371b306 | 91 | { |
ram54288 | 0:a7a43371b306 | 92 | if( m2msecurity_stub::has_value ){ |
ram54288 | 0:a7a43371b306 | 93 | value = NULL; |
ram54288 | 0:a7a43371b306 | 94 | return 5; |
ram54288 | 0:a7a43371b306 | 95 | } |
ram54288 | 0:a7a43371b306 | 96 | return m2msecurity_stub::int_value; |
ram54288 | 0:a7a43371b306 | 97 | } |
ram54288 | 0:a7a43371b306 | 98 | |
ram54288 | 0:a7a43371b306 | 99 | uint32_t M2MSecurity::resource_value_int(SecurityResource res) const |
ram54288 | 0:a7a43371b306 | 100 | { |
ram54288 | 0:a7a43371b306 | 101 | if (res == M2MSecurity::SecurityMode) { |
ram54288 | 0:a7a43371b306 | 102 | return m2msecurity_stub::sec_mode; |
ram54288 | 0:a7a43371b306 | 103 | } |
ram54288 | 0:a7a43371b306 | 104 | else if(res == M2MSecurity::BootstrapServer) { |
ram54288 | 0:a7a43371b306 | 105 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 106 | } |
ram54288 | 0:a7a43371b306 | 107 | else { |
ram54288 | 0:a7a43371b306 | 108 | return m2msecurity_stub::int_value; |
ram54288 | 0:a7a43371b306 | 109 | } |
ram54288 | 0:a7a43371b306 | 110 | } |
ram54288 | 0:a7a43371b306 | 111 | |
ram54288 | 0:a7a43371b306 | 112 | bool M2MSecurity::is_resource_present(SecurityResource) const |
ram54288 | 0:a7a43371b306 | 113 | { |
ram54288 | 0:a7a43371b306 | 114 | return m2msecurity_stub::bool_value; |
ram54288 | 0:a7a43371b306 | 115 | } |
ram54288 | 0:a7a43371b306 | 116 | |
ram54288 | 0:a7a43371b306 | 117 | uint16_t M2MSecurity::total_resource_count() const |
ram54288 | 0:a7a43371b306 | 118 | { |
ram54288 | 0:a7a43371b306 | 119 | return (uint16_t)m2msecurity_stub::int_value; |
ram54288 | 0:a7a43371b306 | 120 | } |
ram54288 | 0:a7a43371b306 | 121 | |
ram54288 | 0:a7a43371b306 | 122 | M2MSecurity::ServerType M2MSecurity::server_type() const |
ram54288 | 0:a7a43371b306 | 123 | { |
ram54288 | 0:a7a43371b306 | 124 | return _server_type; |
ram54288 | 0:a7a43371b306 | 125 | } |
ram54288 | 0:a7a43371b306 | 126 | |
ram54288 | 0:a7a43371b306 | 127 | void M2MSecurity::clear_resources() |
ram54288 | 0:a7a43371b306 | 128 | { |
ram54288 | 0:a7a43371b306 | 129 | |
ram54288 | 0:a7a43371b306 | 130 | } |
ram54288 | 0:a7a43371b306 | 131 | |
ram54288 | 0:a7a43371b306 | 132 | M2MResource* M2MSecurity::get_resource(SecurityResource res) const |
ram54288 | 0:a7a43371b306 | 133 | { |
ram54288 | 0:a7a43371b306 | 134 | return m2msecurity_stub::resource; |
ram54288 | 0:a7a43371b306 | 135 | } |