/ RNS / vendor / platformutils.py
platformutils.py
 1  # Reticulum License
 2  #
 3  # Copyright (c) 2016-2025 Mark Qvist
 4  #
 5  # Permission is hereby granted, free of charge, to any person obtaining a copy
 6  # of this software and associated documentation files (the "Software"), to deal
 7  # in the Software without restriction, including without limitation the rights
 8  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9  # copies of the Software, and to permit persons to whom the Software is
10  # furnished to do so, subject to the following conditions:
11  #
12  # - The Software shall not be used in any kind of system which includes amongst
13  #   its functions the ability to purposefully do harm to human beings.
14  #
15  # - The Software shall not be used, directly or indirectly, in the creation of
16  #   an artificial intelligence, machine learning or language model training
17  #   dataset, including but not limited to any use that contributes to the
18  #   training or development of such a model or algorithm.
19  #
20  # - The above copyright notice and this permission notice shall be included in
21  #   all copies or substantial portions of the Software.
22  #
23  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29  # SOFTWARE.
30  
31  def get_platform():
32      from os import environ
33      if "ANDROID_ARGUMENT" in environ: return "android"
34      elif "ANDROID_ROOT" in environ:   return "android"
35      else:
36          import sys
37          return sys.platform
38  
39  def is_linux():
40      if get_platform() == "linux": return True
41      else: return False
42  
43  def is_darwin():
44      if get_platform() == "darwin": return True
45      else: return False
46  
47  def is_android():
48      if get_platform() == "android": return True
49      else: return False
50  
51  def is_windows():
52      if str(get_platform()).startswith("win"): return True
53      else: return False
54  
55  def use_epoll():
56      if is_linux() or is_android(): return True
57      else: return False
58  
59  def use_af_unix():
60      if is_linux() or is_android(): return True
61      else: return False
62  
63  def platform_checks():
64      if is_windows():
65          import sys
66          if sys.version_info.major >= 3 and sys.version_info.minor >= 8: pass
67          else:
68              import RNS
69              RNS.log("On Windows, Reticulum requires Python 3.8 or higher.", RNS.LOG_ERROR)
70              RNS.log("Please update Python to run Reticulum.", RNS.LOG_ERROR)
71              RNS.panic()
72  
73  def cryptography_old_api():
74      import cryptography
75      if cryptography.__version__ == "2.8": return True
76      else: return False