






"""simple docstring"""





import os
import random
import sys

from . import cryptomath_module as cryptoMath  # noqa: N812
from . import rabin_miller as rabinMiller  # noqa: N812







def      lowerCamelCase__       (							)      ->				None:
  print('Making key files...' )
  make_key_files('rsa'		,				1024 )
  print('Key files generation successful.' )







def      lowerCamelCase__       (							_lowerCamelCase       :		int )      ->				tuple[tuple[int, int], tuple[int, int]]:
  print('Generating prime p...' )
  lowerCamelCase_         =						rabinMiller.generate_large_prime(_lowerCamelCase )
  print('Generating prime q...' )
  lowerCamelCase_         =						rabinMiller.generate_large_prime(_lowerCamelCase )
  lowerCamelCase_         =						p * q

  print('Generating e that is relatively prime to (p - 1) * (q - 1)...' )
  while True:
    lowerCamelCase_         =						random.randrange(2 ** (key_size - 1)		,				2 ** (key_size) )
    if cryptoMath.gcd(_lowerCamelCase		,				(p - 1) * (q - 1) ) == 1:
      break

  print('Calculating d that is mod inverse of e...' )
  lowerCamelCase_         =						cryptoMath.find_mod_inverse(_lowerCamelCase		,				(p - 1) * (q - 1) )

  lowerCamelCase_         =						(n, e)
  lowerCamelCase_         =						(n, d)
  return (public_key, private_key)







def      lowerCamelCase__       (							_lowerCamelCase       :		str		,				_lowerCamelCase       :		int )      ->				None:
  if os.path.exists(F'''{name}_pubkey.txt''' ) or os.path.exists(F'''{name}_privkey.txt''' ):
    print('\nWARNING:' )
    print(
        F'''"{name}_pubkey.txt" or "{name}_privkey.txt" already exists. \n'''
        'Use a different name or delete these files and re-run this program.' )
    sys.exit()

  lowerCamelCase_     ,	lowerCamelCase_         =						generate_key(_lowerCamelCase )
  print(F'''\nWriting public key to file {name}_pubkey.txt...''' )
  with open(F'''{name}_pubkey.txt'''		,				'w' ) as out_file:
    out_file.write(F'''{key_size},{public_key[0]},{public_key[1]}''' )

  print(F'''Writing private key to file {name}_privkey.txt...''' )
  with open(F'''{name}_privkey.txt'''		,				'w' ) as out_file:
    out_file.write(F'''{key_size},{private_key[0]},{private_key[1]}''' )


if __name__ == "__main__":
  main()












"""simple docstring"""





import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


_SCREAMING_SNAKE_CASE					:				Any					    =						importlib.util.find_spec('''s3fs''') is not None

if _has_safs:
  from .safilesystem import SaFileSystem  # noqa: F401

_SCREAMING_SNAKE_CASE					:				List[compression.BaseCompressedFileFileSystem]					    =						[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
  if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
    warnings.warn(F'''A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.''')
  fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)







def      lowerCamelCase__       (							_lowerCamelCase       :		str )      ->				str:
  if "://" in dataset_path:
    lowerCamelCase_         =						dataset_path.split('://' )[1]
  return dataset_path







def      lowerCamelCase__       (							_lowerCamelCase       :		fsspec.AbstractFileSystem )      ->				bool:
  if fs is not None and fs.protocol != "file":
    return True
  else:
    return False







def      lowerCamelCase__       (							_lowerCamelCase       :		fsspec.AbstractFileSystem		,				_lowerCamelCase       :		str		,				_lowerCamelCase       :		str )      ->				int:
  lowerCamelCase_         =						not is_remote_filesystem(_lowerCamelCase )
  if is_local:
    # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
    shutil.move(fs._strip_protocol(_lowerCamelCase )		,				fs._strip_protocol(_lowerCamelCase ) )
  else:
    fs.mv(_lowerCamelCase		,				_lowerCamelCase		,				recursive=_lowerCamelCase )







def      lowerCamelCase__       (							)      ->				None:
  if hasattr(fsspec.asyn		,				'reset_lock' ):
    # for future fsspec>2022.05.0
    fsspec.asyn.reset_lock()
  else:
    lowerCamelCase_         =						None
    lowerCamelCase_         =						None
    lowerCamelCase_         =						threading.Lock()




