| 1 |
|
%% Copyright (c) 2023 Peter Morgan <peter.james.morgan@gmail.com> |
| 2 |
|
%% |
| 3 |
|
%% Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
|
%% you may not use this file except in compliance with the License. |
| 5 |
|
%% You may obtain a copy of the License at |
| 6 |
|
%% |
| 7 |
|
%% http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
|
%% |
| 9 |
|
%% Unless required by applicable law or agreed to in writing, software |
| 10 |
|
%% distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
|
%% See the License for the specific language governing permissions and |
| 13 |
|
%% limitations under the License. |
| 14 |
|
|
| 15 |
|
|
| 16 |
|
-module(msmp). |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
-export([priv_consult/1]). |
| 20 |
|
-export_type([auth_more_data/0]). |
| 21 |
|
-export_type([auth_switch_request/0]). |
| 22 |
|
-export_type([handshake/0]). |
| 23 |
|
-export_type([handshake_response/0]). |
| 24 |
|
-export_type([pdu/0]). |
| 25 |
|
-export_type([u1/0]). |
| 26 |
|
-export_type([u2/0]). |
| 27 |
|
-export_type([u3/0]). |
| 28 |
|
-export_type([u4/0]). |
| 29 |
|
-export_type([u5/0]). |
| 30 |
|
-export_type([u6/0]). |
| 31 |
|
-export_type([u7/0]). |
| 32 |
|
-export_type([u8/0]). |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
-type auth_plugin_name() :: mysql_native_password |
| 36 |
|
| caching_sha2_password. |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
-type character_set() :: integer(). |
| 40 |
|
-type sequence() :: non_neg_integer(). |
| 41 |
|
|
| 42 |
|
-type packet() :: handshake() |
| 43 |
|
| handshake_response(). |
| 44 |
|
|
| 45 |
|
-type pdu() :: #{packet := packet(), sequence := sequence()}. |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
-type handshake() :: #{reserved := binary(), |
| 49 |
|
action := handshake, |
| 50 |
|
character_set := character_set(), |
| 51 |
|
capability_flags_1 := msmp_capabilities:lower(), |
| 52 |
|
capability_flags_2 := msmp_capabilities:upper(), |
| 53 |
|
server_version := binary(), |
| 54 |
|
thread_id := integer(), |
| 55 |
|
auth_plugin_data_part_1 := binary(), |
| 56 |
|
filler := integer(), |
| 57 |
|
status_flags := integer(), |
| 58 |
|
auth_plugin_data_len := integer(), |
| 59 |
|
auth_plugin_data_part_2 := binary(), |
| 60 |
|
auth_plugin_name := auth_plugin_name()}. |
| 61 |
|
|
| 62 |
|
-type handshake_response() :: #{action := handshake_response, |
| 63 |
|
connect_attrs := #{binary() := binary()}, |
| 64 |
|
client_flags := msmp_capabilities:combined(), |
| 65 |
|
character_set := character_set(), |
| 66 |
|
auth_response := binary(), |
| 67 |
|
client_plugin_name := auth_plugin_name(), |
| 68 |
|
max_packet_size := non_neg_integer(), |
| 69 |
|
username := binary()}. |
| 70 |
|
|
| 71 |
|
-type auth_more_data() :: #{action := auth_more_data, |
| 72 |
|
status := fast_auth_success | perform_full_authentication} |
| 73 |
|
| #{action := auth_more_data, |
| 74 |
|
public_key := binary()}. |
| 75 |
|
|
| 76 |
|
-type auth_switch_request() :: #{action := auth_switch_request, |
| 77 |
|
plugin_name := auth_plugin_name(), |
| 78 |
|
plugin_provided_data := binary()}. |
| 79 |
|
|
| 80 |
|
-type u1() :: 0..16#ff. |
| 81 |
|
-type u2() :: 0..16#ff_ff. |
| 82 |
|
-type u3() :: 0..16#ff_ff_ff. |
| 83 |
|
-type u4() :: 0..16#ff_ff_ff_ff. |
| 84 |
|
-type u5() :: 0..16#ff_ff_ff_ff_ff. |
| 85 |
|
-type u6() :: 0..16#ff_ff_ff_ff_ff_ff. |
| 86 |
|
-type u7() :: 0..16#ff_ff_ff_ff_ff_ff_ff. |
| 87 |
|
-type u8() :: 0..16#ff_ff_ff_ff_ff_ff_ff_ff. |
| 88 |
|
|
| 89 |
|
|
| 90 |
|
priv_dir() -> |
| 91 |
8 |
code:priv_dir(?MODULE). |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
priv_consult(Filename) -> |
| 95 |
8 |
phrase_file:consult(filename:join(priv_dir(), Filename)). |