code: def compose_auth_header(
      auth: Union[MutableMapping, str, bytes], registry_addr: str = None
  ) -> str:
      
      if isinstance(auth, Mapping):
          # Validate the JSON format only.
          if "identitytoken" in auth:
              pass
          elif "auth" in auth:
              return compose_auth_header(auth["auth"], registry_addr)
          else:
              if registry_addr:
                  auth["serveraddress"] = registry_addr
          auth_json = json.dumps(auth).encode("utf-8")
      elif isinstance(auth, (str, bytes)):
          # Parse simple "username:password"-formatted strings
          # and attach the server address specified.
          if isinstance(auth, bytes):
              auth = auth.decode("utf-8")
          s = base64.b64decode(auth)
          username, passwd = s.split(b":", 1)
          config = {
              "username": username.decode("utf-8"),
              "password": passwd.decode("utf-8"),
              "email": None,
              "serveraddress": registry_addr,
          }
          auth_json = json.dumps(config).encode("utf-8")
      else:
          raise TypeError("auth must be base64 encoded string/bytes or a dictionary")
      auth = base64.b64encode(auth_json).decode("ascii")
      return auth
docs: Validate and compose base64-encoded authentication header
      with an optional support for parsing legacy-style "user:password"
      strings.
  
      Args:
          auth: Authentication information
          registry_addr: An address of the registry server
  
      Returns:
          A base64-encoded X-Registry-Auth header value