mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-09-24 10:57:22 +00:00
Merge pull request #45 from ronald-cron-arm/projects-and-branches-detection
Projects and Mbed TLS 3.6 detection
This commit is contained in:
@@ -7,17 +7,24 @@
|
||||
|
||||
import os
|
||||
import inspect
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
def looks_like_tf_psa_crypto_root(path: str) -> bool:
|
||||
"""Whether the given directory looks like the root of the PSA Crypto source tree."""
|
||||
return all(os.path.isdir(os.path.join(path, subdir))
|
||||
for subdir in ['include', 'core', 'drivers', 'programs', 'tests'])
|
||||
try:
|
||||
with open(os.path.join(path, 'scripts', 'project_name.txt'), 'r') as f:
|
||||
return f.read() == "TF-PSA-Crypto\n"
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
def looks_like_mbedtls_root(path: str) -> bool:
|
||||
"""Whether the given directory looks like the root of the Mbed TLS source tree."""
|
||||
return all(os.path.isdir(os.path.join(path, subdir))
|
||||
for subdir in ['include', 'library', 'programs', 'tests'])
|
||||
try:
|
||||
with open(os.path.join(path, 'scripts', 'project_name.txt'), 'r') as f:
|
||||
return f.read() == "Mbed TLS\n"
|
||||
except FileNotFoundError:
|
||||
return False
|
||||
|
||||
def looks_like_root(path: str) -> bool:
|
||||
return looks_like_tf_psa_crypto_root(path) or looks_like_mbedtls_root(path)
|
||||
@@ -122,3 +129,16 @@ def guess_tf_psa_crypto_root(root: Optional[str] = None) -> str:
|
||||
return root
|
||||
else:
|
||||
raise Exception('TF-PSA-Crypto source tree not found')
|
||||
|
||||
def is_mbedtls_3_6() -> bool:
|
||||
"""Whether the working tree is an Mbed TLS 3.6 one or not
|
||||
|
||||
Return false in we are in TF-PSA-Crypto or in Mbed TLS but with a version
|
||||
different from 3.6.x.
|
||||
Raise an exception if we are neither in Mbed TLS nor in TF-PSA-Crypto.
|
||||
"""
|
||||
root = guess_project_root()
|
||||
if not looks_like_mbedtls_root(root):
|
||||
return False
|
||||
with open(os.path.join(root, 'include', 'mbedtls', 'build_info.h'), 'r') as f:
|
||||
return re.search(r"#define MBEDTLS_VERSION_NUMBER.*0x0306", f.read()) is not None
|
||||
|
||||
Reference in New Issue
Block a user