From 26907107b3471a867c8faa910d8c7fe22337ea94 Mon Sep 17 00:00:00 2001 From: Mike Kinney Date: Mon, 6 Dec 2021 21:09:24 -0800 Subject: [PATCH] move pskToString into util --- meshtastic/node.py | 19 +------------------ meshtastic/util.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/meshtastic/node.py b/meshtastic/node.py index 27e49ac..27261f4 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -60,24 +60,7 @@ import base64 from typing import * from google.protobuf.json_format import MessageToJson from . import portnums_pb2, apponly_pb2, admin_pb2, channel_pb2 -from .util import stripnl, Timeout - - - -def pskToString(psk: bytes): - """Given an array of PSK bytes, decode them into a human readable (but privacy protecting) string""" - if len(psk) == 0: - return "unencrypted" - elif len(psk) == 1: - b = psk[0] - if b == 0: - return "unencrypted" - elif b == 1: - return "default" - else: - return f"simple{b - 1}" - else: - return "secret" +from .util import pskToString, stripnl, Timeout class Node: diff --git a/meshtastic/util.py b/meshtastic/util.py index c0cce5b..927a28b 100644 --- a/meshtastic/util.py +++ b/meshtastic/util.py @@ -13,6 +13,22 @@ import serial.tools.list_ports blacklistVids = dict.fromkeys([0x1366]) +def pskToString(psk: bytes): + """Given an array of PSK bytes, decode them into a human readable (but privacy protecting) string""" + if len(psk) == 0: + return "unencrypted" + elif len(psk) == 1: + b = psk[0] + if b == 0: + return "unencrypted" + elif b == 1: + return "default" + else: + return f"simple{b - 1}" + else: + return "secret" + + def stripnl(s): """remove newlines from a string (and remove extra whitespace)""" s = str(s).replace("\n", " ")